oracle listagg 排序,oracle 行转列 listagg与wm_concat

wm_concat 和listagg 函数都可以实现对(单个或组合)列的合并,也可以看成是对某一列的“SUM”,这俩个函数功能相同,listagg是在11.2的版本中才首次出现的,wm_concat在12c版本中被取消。

常见用法

select t.job,listagg(t.ename,',') within group(order by hiredate asc) from scott.emp t group by t.job;

select t.job,wm_concat(t.ename) from scott.emp t group by t.job;

--去重

with tb as(

select sys_guid() id,'t1' name, 'CLERK' job from dual

union select sys_guid() id,'t1' name, 'SALESMAN' job from dual

union select sys_guid() id,'t1' name, 'MANAGER' job from dual

union select sys_guid() id,'t1' name, 'CLERK' job from dual

union select sys_guid() id,'t2' name, 'MANAGER' job from dual

union select sys_guid() id,'t2' name, 'MANAGER' job from dual

)

select t.name, wm_concat(distinct t.job) jobs from

你可能感兴趣的:(oracle,listagg,排序)