Oracleストアドプロシージャ(PL/SQL)をPostgreSQL(pl/pgsql)に移行する必要があります。私はそれを行う方法を理解することはできません。Oracle PL/SQLプロシージャをPostgreSQLに移行する方法
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;
私は、単純な 'tabline:= string_to_array(strline、 ';')'を使って、Postgresで行の分割をはるかに簡単に行うことができると思います。あなたが 'utl_file'と同等のものを探しているのなら、orafceという拡張子を使うことができます:https://github.com/orafce/orafce –