1. 程式人生 > >oracle管道流函式,字串按照逗號分隔,函式中迴圈

oracle管道流函式,字串按照逗號分隔,函式中迴圈

1.定義物件類

CREATE OR REPLACE TYPE "FUNC_GDT_QUERY" IS object
(
  totalRMB       NUMBER(14, 2), 
  agencyCredit   NUMBER(14, 2), 
  dollarRMB      NUMBER(14, 2), 
  bankAccept     NUMBER(14, 2), 
  letterOfCredit NUMBER(14, 2) 
)

2.建立物件類的表型別

CREATE OR REPLACE TYPE "TAB_GDT_QUERY" is table of FUNC_GDT_QUERY

3.建立包,定義函式

create or replace package PKG_GDT_QUERY is
  function F_GDT_QUERY(cltnos      in varchar2,
                            bankcodes   in varchar2,
                            actdate     in varchar2,
                            handleEnter in varchar2)
    return TAB_GDT_QUERY
    PIPELINED;
end PKG_GDT_QUERY;

4.實現包體

create or replace package body PKG_GDT_QUERY is
  function F_GDT_QUERY(cltnos      in varchar2,
                            bankcodes   in varchar2,
                            actdate     in varchar2,
                            handleEnter in varchar2)
    return TAB_GDT_QUERY
    PIPELINED is
--定義變數 v_result FUNC_GDT_QUERY := FUNC_GDT_QUERY(NULL, NULL, NULL, NULL, NULL);
--將字串按照逗號分隔,並進行迴圈 CURSOR cltno_cursor IS select regexp_substr(F_GDT_QUERY.cltnos, '[^,]+', 1, rownum) as cltno from dual connect by rownum <= length(regexp_replace(F_GDT_QUERY.cltnos, '[^,]', null)) + 1; CURSOR bankcode_cursor IS select regexp_substr(F_GDT_QUERY.bankcodes, '[^,]+', 1, rownum) as bankcode from dual connect by rownum <= length(regexp_replace(F_GDT_QUERY.bankcodes, '[^,]', null)) + 1; begin --進行迴圈 for rec1 in cltno_cursor Loop for rec2 in bankcode_cursor Loop --rec1.cltno,,,,rec2.bankcode //具體查詢 。。。。。。。。。。。。 //賦值 v_result.totalRMB := ???; end loop; end loop; PIPE ROW(v_result); return; end F_GDT_QUERY; end PKG_GDT_QUERY;