Oracle wm_concat函数 列合并成一行
函数wm_concat(列名),该函数可以把列值以","号分隔起来,并显示成一行,接下来上例子,看看这个神奇的函数如何应用准备测试数据
create table test(id number,name varchar2(20)); insert into test values(1,'a'); insert into test values(1,'b'); insert into test values(1,'c'); insert into test values(2,'d'); insert into test values(2,'e');
效果1 : 行转列 ,默认逗号隔开
select wm_concat(name) name from test;
效果2: 把结果里的逗号替换成"|"
select replace(wm_concat(name),',','|') from test;
效果3: 按ID分组合并name
select id,wm_concat(name) name from test group by id;