Oracle数据库中的wm_concat

Oracle数据库中的wm_concat

背景

在实际开发中遇到需要将符合要求的几行数据合并,即如下:

id 字段一 字段二 字段三
1 1001 A time
1 1001 B time
合并为:
id 字段一 字段二 字段三
-- ----- ----- -----
1 1001 A,B time

解决方法:

select id, 字段一,字段三 to_char(wm_concat(字段二))
from (select id id, 字段一,字段二,字段三
from camp_coupon_acquire_channel)
group by id, 字段一,字段三;

其他方法

一致wm_concat()函数在高版本的Oracle中已经不支持,所以可以使用
listagg() within group(order by);
listagg(字段二, ',') within group(order by id)

posted @ 2023-03-15 15:26  zzzzzzzn  阅读(103)  评论(0)    收藏  举报