Oracle管道函數(shù)(Pipelined Table Function)oracle管道函數(shù)
1、管道函數(shù)即是可以返回行集合(可以使嵌套表nested table 或數(shù)組 varray)的函數(shù),我們可以像查詢物理表一樣查詢它或者將其賦值給集合變量。
2、管道函數(shù)為并行執(zhí)行,在普通的函數(shù)中使用dbms_output輸出的信息,需要在服務(wù)器執(zhí)行完整個函數(shù)后一次性的返回給客戶端。如果需要在客戶端
實時的輸出函數(shù)執(zhí)行過程中的一些信息,在oracle9i以后可以使用管道函數(shù)(pipeline function)。
3、關(guān)鍵字PIPELINED表明這是一個oracle管道函數(shù),oracle管道函數(shù)的返回值類型必須為集合,在函數(shù)中,PIPE ROW語句被用來返回該集合的單個元素,函數(shù)以一個空的RETURN 語句結(jié)束,以表明它已經(jīng)完成。
原文:https://blog.csdn.net/indexman/article/details/27580517
1.簡單例子
-
--PIPELINED 表示管道函數(shù)
-
--PIPE ROW 返回該集合的單個元素
-
--創(chuàng)建type類型 t_table
-
create or replace type t_table is table of number
-
--創(chuàng)建函數(shù)
-
create or replace function f_pipe(s number)
-
return t_table pipelined --返回t_table
-
as
-
v_number number;
-
begin
-
for i in 1..s loop
-
v_number := i;
-
pipe row(v_number);--返回集合單個的值
-
end loop;
-
return;
-
end f_pipe;
-
--測試函數(shù)
-
select * from table(f_pipe(5))
?結(jié)果圖
2.復(fù)雜一點的例子
-
--創(chuàng)建一個表類型
-
create or replace type obj_table as object
-
(
-
id int,
-
name varchar2(50)
-
)
-
--創(chuàng)建返回多個表類型的類型
-
create or replace type list_table is table of obj_table
-
--創(chuàng)建函數(shù)
-
create or replace function f_pipes(s number)
-
return list_table pipelined --list_table返回類型
-
as
-
v_obj_table obj_table;
-
begin
-
for i in 1..s loop
-
v_obj_table := obj_table(i,to_char(i*i));
-
pipe row(v_obj_table);--返回obj_table類型的單列數(shù)據(jù)
-
end loop;
-
return;
-
end f_pipes;
-
--測試函數(shù)
-
select * from table(f_pipes(5))
結(jié)果圖:文章來源:http://www.zghlxwxcb.cn/news/detail-636379.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-636379.html
到了這里,關(guān)于oracle的管道函數(shù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!