oracle 管道表函数

 

 

------创建一个类型

create or replace type whiteListType  as object(
   spid  number ,
   spname varchar2(200),
   spcode varchar2(200),
   listname varchar2(200),
   mdncount number

-----创建一个引用

CREATE OR REPLACE TYPE "WHITE_LIST_TYPE_ARRAY"                                                                           IS array(10000) OF WHITLISTCOUNT

-----创建function

create or replace function GETWHITELIST(
spid  in number
)
return whitelistArray pipelined
is
  v_whiteListType whiteListType ;
  strsql      varchar2(1000);
 -- spinfos     whitelistArray;
  rs          SYS_REFCURSOR;
  id          number;
  sp_name     varchar2(200);
  sp_code     varchar2(200);
  sp_status   number;
  sp_type     number;
  mdn_count   number;
begin

  ------------------------??????-----------------------------
  -- ??????? ??? id
  strsql := 'select  id, sp_code, sp_name ,sp_type  ,sp_status  from NM_SP_INFO where id != 0  ';
  if spid >0  then
  strsql := strsql||' and id = '''||spid||'''';
  end if ;
  strsql := strsql || ' order by id';
  -- ???? ?????????
  open rs for strsql;
  loop
    fetch rs
      into id, sp_name, sp_code,sp_type ,sp_status;
    exit when rs%NOTFOUND;
    strsql := 'select count(mdn) from NM_NET_USER_' || id || ' where 1=1 and status <>4';
    execute immediate strsql into mdn_count;
      if mdn_count > 0 then
      v_whiteListType :=whiteListType(id , sp_name , sp_code , '',mdn_count );

      pipe row(v_whiteListType) ;----
    end if ;
  end loop;
  close rs ;
  return ;
end GETWHITELIST;

 

 

 

----执行

select * from table(GETWHITELIST(0))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值