2 qq 17579189 qq_17579189 于 2015.07.27 09:30 提问

oracle查询,多个字段合拼为一个字段(有图)

图片说明

5个回答

danielinbiti
danielinbiti   Ds   Rxr 2015.07.27 09:39
已采纳

oracle 的分组字符串合并
http://www.itpub.net/thread-1702620-1-1.html

danielinbiti
danielinbiti 回复qq_17579189: 不客气,如果解决了,有时间顺手采纳一下
2 年多之前 回复
qq_17579189
qq_17579189 谢谢
2 年多之前 回复
lzp_lrp
lzp_lrp   Ds   Rxr 2015.07.28 08:50

试试这个

select id, ltrim(sys_connect_by_path(name, ','), ',') name
from (select id,
name,
row_number() over(partition by id order by name) rn,
count(*) over(partition by id) cnt
from table) t
where rn = cnt
start with rn = 1
connect by prior id = id
and prior rn = rn - 1
order by id;

lzp_lrp
lzp_lrp   Ds   Rxr 2015.07.28 08:50

把table换成你的表名,id和name为你表里的字段

xiaonan
xiaonan   2015.07.29 12:04

用函数wmsys.wm_concat
select id, wmsys.wm_concat(name) as names
from table
group by id
order by id

xiaonan
xiaonan   2015.07.29 12:04

用函数wmsys.wm_concat
select id, wmsys.wm_concat(name) as names
from table
group by id
order by id

Csdn user default icon
上传中...
上传图片
插入图片