我需要将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;
答案 0 :(得分:0)
看起来非常简单。
RETURNS void
定义一个函数。tabline
计算为text[]
(text
数组)。请参阅文档how to handle arrays。adminpack
contrib模块中的函数写入数据库服务器上的文件。The documentation将帮助您解决重新问题。