字串分隔 (抄自 atgc的部落格)

longwansheng發表於2007-02-01

SQL> select * from table(str2table('TEST1;12;123;55;99MOON;'));

ACC
--------------------------------------------------
TEST1
2
123
55
99MOON

[@more@]

create or replace type acc_type as object(acc varchar2(50))

/

create or replace type acc_table as table of acc_type/

create or replace function str2table (acc_str in varchar2) return acc_table pipelined

is

v_str varchar2
(30000) := acc_str;
v_acc varchar2(30);
v_acc_end pls_integer;begin

loop

v_acc_end
:= instrb(v_str,';');

exit
when (v_acc_end=0 or v_str is null);
v_acc := substrb(v_str,1,v_acc_end);
v_str := ltrim(v_str,v_acc);
pipe row(acc_type(rtrim(v_acc,';')));
end loop;

return;
end;

/

SQL> select * from table(str2table('TEST1;12;123;55;99MOON;'));

ACC
--------------------------------------------------
TEST1
2
123
55
99MOON

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/92289/viewspace-896476/,如需轉載,請註明出處,否則將追究法律責任。

相關文章