[quote]
如题,比如表(table_a)内容:
id name
1 zs
2 ls
3 as
能够通过一条sql语句,输出 'zs,ls,as'
11g里面用listagg,10g里面用wm_concat
select listagg(name,',') within (order by id) from table;
select wm_concat(name) from table;
select to_char(wm_concat(name)) names from table_a ;
其他的例子:code可以对应多个name
select code, to_char(wm_concat(name) ) up_key
from match_code
WHERE code = '409001'
group by code;
[/quote]
如题,比如表(table_a)内容:
id name
1 zs
2 ls
3 as
能够通过一条sql语句,输出 'zs,ls,as'
11g里面用listagg,10g里面用wm_concat
select listagg(name,',') within (order by id) from table;
select wm_concat(name) from table;
select to_char(wm_concat(name)) names from table_a ;
其他的例子:code可以对应多个name
select code, to_char(wm_concat(name) ) up_key
from match_code
WHERE code = '409001'
group by code;
[/quote]
本文介绍了如何在Oracle 11g和10g中使用SQL聚合函数LISTAGG和WM_CONCAT来处理表中的数据,实现将同一字段的多条记录合并成一个字符串的功能,并提供了具体的SQL语句示例。

被折叠的 条评论
为什么被折叠?



