4

我正在将我的数据库服务器从 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;
4

1 回答 1

3

您唯一需要更改的是“围绕”函数的代码。Oracle 使用与 Postgres 不同的“标题”。

所以 PL/SQL 中的函数看起来像这样。我只更改了开头的 CREATE OR REPLACE 和 final 之后的部分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

于 2013-09-26T13:14:30.763 回答