如果需要在客戶端實(shí)時(shí)的輸出函數(shù)執(zhí)行過(guò)程中的一些信息,在oracle9i以后可以使用管道函數(shù)(pipeline function)。
--創(chuàng)建一個(gè)集合接受返回的值
1st.create or replace type type_split as table of varchar2(4000);
--創(chuàng)建管道函數(shù)
create or replace function split(p_string varchar2, p_sep varchar2 := ',') return type_split pipelined
--dbms_output輸出的信息,需要在服務(wù)器執(zhí)行完整個(gè)函數(shù)后一次性的返回給客戶端
--pipelined 表明這是一個(gè)管道函數(shù),oracle管道函數(shù)的返回值類型必須為集合
--PIPE ROW語(yǔ)句被用來(lái)返回該集合的單個(gè)元素
as
v_string varchar2(4000) := p_string;
idx Number;
begin
loop
--idx為第一個(gè),所在的位置
idx := instr(v_string, p_sep);
if idx > 0 then
--,前面的數(shù)據(jù)加入Row/,后面的數(shù)據(jù)為下個(gè)循環(huán)使用的字符串
pipe row(substr(v_string, 1, idx - 1));
v_string := substr(v_string, idx + length(p_sep));
else
exit;
end if;
end loop;
--執(zhí)行完后需return
return ;
end;
test:
select a.cust_po,b.column_value proqepi from
(
select cust_po,proqepi
from cux_custpo_info_t
where cust_po='PX90806001-4'
) a,(table(split(a.proqepi,','))) b
以上所述是小編給大家介紹的oracle管道函數(shù)的用法(一行拆為多行),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!