本函数用途:返回一个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 GetCSClient 14 ( 15 /* 16 程式代号:GetCSClient 17 程式名称: 18 传入参数: 19 传回值: 20 备注: 21 范例:select * from table(GetCSClient(‘Shadowxiong‘)); 22 版本变更: 23 xx. YYYY/MM/DD VER AUTHOR COMMENTS 24 01. 2015/08/28 1.00 Anne_Han New Create 25 */ 26 P_Usercode varchar2 27 ) 28 return tabtemp PIPELINED 29 as 30 s_usercode varchar2(32767); 31 s_username varchar2(32767); 32 v objtable; 33 begin 34 for myrow in (select CShortName,CEnglishName from mv_liclientbaseinfo order by CShortName) 35 loop 36 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 RETURN 11 END 12 13 --调用Function 14 SELECT * FROM dbo.GetCSClient(‘shadowxiong‘)
时间: 2024-12-30 03:22:03