Oracle pipeline table functions

Source: Internet
Author: User

------ Create a type
 
Create or replace type whiteListType as object (
Spid number,
Spname varchar2 (200 ),
Spcode varchar2 (200 ),
Listname varchar2 (200 ),
Mdncount number
 
----- Create a reference
 
Create or replace type "WHITE_LIST_TYPE_ARRAY" IS array (10000) OF WHITLISTCOUNT
 
----- Create a 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;
 
 
 
 
 
 
 
---- Execution
 
Select * from table (GETWHITELIST (0 ))
From java Xiaosheng

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.