天地不仁,以万物为刍狗!
将表格的某一列转换成逗号分隔的字符串的另类方法
上一篇 /
下一篇 2007-06-15 00:00:00
/ 个人分类:oracle
将表格的某一列转换成逗号分隔的字符串的另类方法
A:dbms_utility.table_to_comma的使用
t1V1wt]9x^En0一:首先建立测试表ITPUB个人空间"_([F^WK
create table table1ITPUB个人空间
]$o wds3X
(ITPUB个人空间7lU
~eH0y,a
dz varchar2(100)ITPUB个人空间4q\
zm8AD%E,Z
)ITPUB个人空间8B&Sd]:Zm'b:Y
insert into table1 values('v');ITPUB个人空间'q
m+j(vS4k'u
insert into table1 values('dywm');ITPUB个人空间]Z2iE(Zk
commit;
SQL> select * from table1;
DZITPUB个人空间!?
|-Yv,u4J
--------------------------------------------------------------------------------
5br7Rq yZ0v
]]&SPO0dywm
二:建立存储过程
,b1f%r'R'l0create or replace procedure test_column_row asITPUB个人空间-P7eb;p7AG'X5btM
qq1 dbms_utility.uncl_array;ITPUB个人空间4R2g6iX^
l_tablen number;
$e%SOU$g,EH0 l_tab varchar2(1000);
gp!H9@*BCC;N0begin
[ \!Q#Qc,^0 select dz bulk collect into qq1 from table1;
*t:\k
wnBht&L3jyH0 dbms_utility.table_to_comma(qq1, l_tablen, l_tab);ITPUB个人空间4oE-};\2OL;K
dbms_output.put_line(l_tab);ITPUB个人空间'~/~&Q$r"O!{%Kx7z+n.W
end;
三:运行结果如下:ITPUB个人空间@7B}X$v4i7l{
SQL> set serveroutput onITPUB个人空间Do
N:T&k(gm.M+G!^z(Q
SQL> execute test_column_row;
v,dywm
PL/SQL procedure successfully completed
附:字符串<=>table相互转换的例子
5A-[9dj8~3J@Ux0create or replace procedure schema_table asITPUB个人空间bVx^#Uy+]
/*ITPUB个人空间v2ZV,TM
]
把字符串变成tableITPUB个人空间&X