標籤:
本函數用途:返回一個Table
在Oracle中實現,範例:
1 --在Types中: 2 create or replace type objTable as object 3 ( 4 s_usercode varchar2(32767), 5 s_username varchar2(32767) 6 ); 7 8 CREATE OR REPLACE TYPE tabTemp AS TABLE OF objtable; 9 10 11 --在Function中:12 --使用Pipeline管道函數和Pipe row()13 create or replace function GetCSClient14 (15 /*16 程式代號:GetCSClient17 程式名稱:18 傳入參數:19 傳回值:20 備忘:21 範例:select * from table(GetCSClient(‘Shadowxiong‘));22 版本變更: 23 xx. YYYY/MM/DD VER AUTHOR COMMENTS24 01. 2015/08/28 1.00 Anne_Han New Create 25 */26 P_Usercode varchar227 ) 28 return tabtemp PIPELINED29 as30 s_usercode varchar2(32767);31 s_username varchar2(32767);32 v objtable;33 begin34 for myrow in (select CShortName,CEnglishName from mv_liclientbaseinfo order by CShortName)35 loop36 v:=objtable(myrow.CShortName, myrow.CEnglishName);37 PIPE ROW (v);38 end loop;39 40 RETURN;41 42 end GetCSClient;
在SQL Service中實現,範例:
1 --在Function中: 2 CREATE FUNCTION [dbo].[GetCSClient] (@USER_CODE NVARCHAR(30)) 3 RETURNS @objTable TABLE (ClientId nvarchar(15),CLIENTNAME nvarchar(150)) 4 AS 5 BEGIN 6 INSERT INTO @objTable(ClientId,CLIENTNAME) 7 SELECT CLIENTID,CLIENTNAME FROM CLIENT WITH(NOLOCK) 8 ORDER BY CLIENTID 9 10 RETURN11 END12 13 --調用Function14 SELECT * FROM dbo.GetCSClient(‘shadowxiong‘)
在Oracle/SQL Service中通過Function返回Table