繁体   English   中英

如何将Oracle PL / SQL过程迁移到PostgreSQL

[英]How to migrate an Oracle PL/SQL procedure to PostgreSQL

我需要将Oracle存储过程(PL / SQL)迁移到PostgreSQL(pl / pgsql)。 我不知道该怎么做。

Procedure Check_File ( strLine in varchar2 , lngRecord in number ) is
  type tab_str is table of varchar2(500) index by binary_integer;
  tabline   tab_str;
  intp1     integer;
  intp2     integer;
  intsize   integer;
begin

  -- Split line into table
  intp1 := 1 ;
  intp2 := instr ( strline , ';' , intp1 ) ;
  intsize := 0;
  while intp2 != 0 loop
    intsize := intsize + 1 ;
    tabline(intsize) := trim(substr ( strLine , intp1 , intp2-intp1 ));
    intp1 := intp2 + 1 ;
    intp2 := instr ( strline , ';' , intp1 ) ;
  end loop;
  intsize := intsize + 1 ;
  tabline(intsize) := trim(substr ( strLine , intp1 ));

  if intsize <> 23 then
    utl_file.put_line ( olog , 'Block - Record ' || lngRecord || ' - Incorrect number of fields') ;
    raise oExcept;
  end if;
end;

这就是我所做的:

CREATE OR REPLACE FUNCTION Check_File ( strLine in text , lngRecord in bigint ) RETURNS VOID AS $body$
DECLARE

  intp1     integer;
  intp2     integer;
  intsize   integer;


   -- CREATE TYPE tab_str AS (tab2 text[]);  
   tabline   tab_str;
BEGIN

    -- Split line into table
    intp1 := 1 ;
    intp2 := instr ( strline , ';' , intp1 ) ;
    intsize := 0;
    while intp2 != 0 loop
      intsize := intsize + 1 ;
      tabline(intsize) := trim(substring(strLine  from intp1  for intp2-intp1 ));
      intp1 := intp2 + 1 ;
      intp2 := instr ( strline , ';' , intp1 ) ;
    end loop;
    intsize := intsize + 1 ;
    tabline(intsize) := trim(substring(strLine  from intp1 ));

    if intsize <> 23 then
      utl_file.put_line ( olog , 'Block - Record ' || lngRecord || ' - Incorrect number of fields') ;
      raise oExcept;
    end if;

END;
$body$
LANGUAGE PLPGSQL;

似乎很简单。

  • 如果您不需要返回任何内容,请使用RETURNS void定义一个函数。
  • 将Tabline tablinetext[]text数组)。 请参阅文档如何处理数组
  • 使用adminpack contrib模块中的函数来写入数据库服务器上的文件。

该文档将帮助您解决重整问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM