oracle 파이프 함수 PIPELINED

6709 단어 PIPELINED
먼저 인터넷 에서 검색 한 비교적 간단 한 파이프 함 수 를 사용 하 는 예 를 들 어 보 겠 습 니 다.
 
--      ,            ,            。   
create or replace type my_type as table of varchar2(4000);   
  
--         
--       : "[b]pipelined[/b]"   
--          :"[b]pipe row(...)[/b]"   
create or replace function func_pipe_test return my_type   
  pipelined is  
begin  
  for i in reverse 1 .. 10 loop   
    pipe row(i);   
  end loop;   
  
end;   
  
--         
select * from table(func_pipe_test);  

 
다음은 프로젝트 에 사 용 된 것 을 결합 하여 여러분 과 공유 합 니 다.
 
 
--      ,            ,            
CREATE OR REPLACE TYPE "IF_SET_TAB"
 AS TABLE OF RET_ROW
--          (            )
CREATE OR REPLACE TYPE "RET_ROW"
 
   AS OBJECT(Rval  int)
--

CREATE OR REPLACE FUNCTION FB_IS_SETACCOUNT
 (
 NO   INT
 )

 RETURN  IF_SET_TAB  PIPELINED
 IS
 RET_ROW0  RET_ROW:=RET_ROW(NULL);
 bizType   fb_business.biz_type%TYPE;
 num   int;
 ret   int :=0;
 BEGIN
 SELECT  biz_type  INTO  bizType  FROM  business  WHERE   bid=FB_IS_SETACCOUNT.NO;
 IF  (bizType = '101')  THEN
    SELECT  count(*)  into  num   FROM    ACCOUNTS  WHERE   ACCOUNT_TYPE  IN('CREDIT','DEPOSIT','INTREST.INCOME','WITHHOLDING')
    AND  BID =FB_IS_SETACCOUNT.NO   and   account_no is  not  null;
    if  num = 4   then
    ret := 1;
    end if;
  ELSIF(bizType = '104')    THEN
    SELECT  count(*)  into  num  from   ACCOUNTS  WHERE   ACCOUNT_TYPE  IN('CREDIT','DEPOSIT','CONSIGN.DEPOSIT','CHARGE.PAY','CHARGE.INCOME','CONSIGN.INTREST')
      AND  BID =FB_IS_SETACCOUNT.NO  and   account_no is  not  null;
    if  num = 6   then
    ret := 1;
    end  if;
   END   IF;
   
   RET_ROW0.Rval := FB_IS_SETACCOUNT.ret; 
   pipe row(RET_ROW0);  --    
   return;
 END;

 다음은 파이프 함수 에서 배열 구조 와 유사 한 함 수 를 되 돌려 줍 니 다.
  
  
 
--      ,            ,            

CREATE OR REPLACE TYPE "HN_STAT_KM_BALANCE_TAB"
   AS TABLE OF HN_STAT_KM_BALANCE_ROW      
   
--          (       )
CREATE OR REPLACE TYPE "HN_STAT_KM_BALANCE_ROW"                                                                                                                                                   AS OBJECT
 (no             varchar2(10),
  name            varchar2(100),
  treeNo          varchar2(20),
  currentAmount            NUMBER(20,2),
  notifyAmount     NUMBER(20,2),
  threeMonthAmount      NUMBER(20,2),
  sixMonthAmount     NUMBER(20,2),
  oneYearAmount     NUMBER(20,2),
  twoYearAmount            NUMBER(20,2),
  threeYearAmount             NUMBER(20,2),
  fiveYearAmount         NUMBER(20,2),
  MoreYearAmount          NUMBER(20,2),
  consignDepositAmount        NUMBER(20,2),
  shortLoanAmount          NUMBER(20,2),
  longLoanAmount          NUMBER(20,2),
  consignLoanAmount          NUMBER(20,2),
  totalAmount          NUMBER(20,2)
)

--     
CREATE OR REPLACE FUNCTION HN_STAT_KM_BALANCE(
qryCltno  varchar2,
qryTreeNo varchar2,
containFlag  Integer,
qrydate IN DATE,
qryType Integer,    --null--
bz IN varchar2
)
RETURN HN_STAT_KM_BALANCE_TAB PIPELINED
IS
RET  HN_STAT_KM_BALANCE_ROW:=HN_STAT_KM_BALANCE_ROW(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
anothorTreeNo varchar2(20);
qrybz varchar2(1);
BEGIN

  qrybz := bz;
  if(bz is null) then
      qrybz := 'R';
  end if; 
  --      
  if qryType is null then
     for rec3 in(select no,treeno,name from table(HN_STAT_SHEET_CLIENT(qryCltno,qryTreeNo,containFlag,null)))
    loop
        RET := HN_STAT_KM_BALANCE_ROW(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

        ret.no := rec3.no;
        ret.treeNo := rec3.treeno;
        ret.name := rec3.name;
        ret.totalAmount := 0;
        ret.threeMonthAmount := 0;
        ret.sixMonthAmount := 0;
        ret.oneYearAmount := 0;
        ret.notifyAmount := 0;
        ret.twoYearAmount:= 0;
        ret.threeYearAmount:=0;
        ret.fiveYearAmount := 0;
        ret.MoreYearAmount := 0;
        if ret.treeNo = '001001000%' then
           anothorTreeNo := '001001';
        else
           anothorTreeNo := '000';
        end if;

        --          ,    ,      
           
         for  rec in (select  sum(b.rval) amount,a.kmh  kmh  from  acnt  a,table(NS_GetRval(qrybz,a.no, qrydate, 0)) b,client n
            where    a.clientid=n.cltno  and  a.bz = qrybz  and  b.rval != 0
            and (n.treeno like ret.treeNo or n.treeno = anothorTreeNo)
            group by a.kmh  order by a.kmh)
        loop
           if (rec.kmh = '*') then
                 ret.threeMonthAmount := ret.threeMonthAmount + rec.amount;
           elsif(rec.kmh = '*') then
                 ret.sixMonthAmount := ret.sixMonthAmount + rec.amount;
           elsif(rec.kmh = '*') then
                 ret.oneYearAmount := ret.oneYearAmount + rec.amount;
           elsif(rec.kmh = '*') then
                 ret.notifyAmount := ret.notifyAmount + rec.amount;
           elsif(rec.kmh = '*') then
                 ret.twoYearAmount := ret.twoYearAmount + rec.amount;
           elsif(rec.kmh = '*') then
                 ret.threeYearAmount := ret.threeYearAmount + rec.amount;
           elsif(rec.kmh = '*') then
                 ret.fiveYearAmount := ret.fiveYearAmount + rec.amount;
           elsif(rec.kmh = '*') then
                 ret.MoreYearAmount := ret.MoreYearAmount + rec.amount;
           end if;
           
             ret.totalAmount := ret.totalAmount + rec.amount;
          
        end loop;
         PIPE ROW(RET);
    end loop;
  end if;
  RETURN;
END HN_STAT_KM_BALANCE;

좋은 웹페이지 즐겨찾기