簡體   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