我正在将我的数据库服务器从PostgreSQL迁移到Oracle 11g。我尝试了各种工具,如Squirrel SQL。但是大多数迁移工具都支持迁移表和视图。我无法找到迁移我的程序和功能的解决方案。我可以通过什么方式迁移函数和过程。请找到以下功能之一。
CREATE OR REPLACE FUNCTION hrms.fngetstatus(iactdate character varying, ideactdate character varying)
RETURNS character varying AS
$BODY$
returnval VARCHAR (1);
BEGIN
IF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') IS NULL
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') IS NULL
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') =
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') =
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (ideactdate, 'mm/dd/yyyy') >=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (iactdate, 'mm/dd/yyyy') is null
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
END IF;
RETURN returnval;
END$BODY$
LANGUAGE edbspl VOLATILE SECURITY DEFINER
COST 100;
ALTER FUNCTION hrms.fngetstatus(character varying, character varying)
OWNER TO enterprisedb;
答案 0 :(得分:3)
您唯一需要改变的是代码“围绕”该功能。 Oracle使用与Postgres不同的“标题”。
因此PL / SQL中的函数看起来像这样。我只更改了开头的CREATE OR REPLACE和最后END
之后的部分。
CREATE OR REPLACE FUNCTION fngetstatus(iactdate varchar, ideactdate varchar)
RETURN varchar
AS
returnval VARCHAR (1);
BEGIN
IF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') IS NULL
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') IS NULL
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') =
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') =
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (ideactdate, 'mm/dd/yyyy') >=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (iactdate, 'mm/dd/yyyy') is null
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'A';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
ELSIF TO_DATE (iactdate, 'mm/dd/yyyy') >
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
AND TO_DATE (ideactdate, 'mm/dd/yyyy') <=
TO_DATE (TO_CHAR (SYSDATE, 'mm/dd/yyyy'), 'mm/dd/yyyy')
THEN
returnval := 'D';
END IF;
RETURN returnval;
END;
/
这是一个SQLFiddle示例:http://sqlfiddle.com/#!4/94990/2