listagg within group

oracle 多行合并成一行: listagg within group

可以和递归方法一起使用查询路径:

例如:

SELECT LISTAGG(t.FOLDER_NAME, '/') WITHIN GROUP(ORDER BY LEVEL DESC) AS FOLDER_NAME

FROM BAS_FOLDER_TREE t
START WITH ID = '1470'
CONNECT BY PRIOR PID = ID;

查询结果:知识维度/人力资源测试账号看不到的维度/娱乐维度

可以解决查询路径的问题。

 

单独的使用listagg within group:

SELECT ID, listagg(NAME, ',') within group(ORDER BY ID) AS NAMES FROM DEMO T GROUP BY ID

查询结果:

 

posted @ 2019-01-21 17:36  嘻嘻哈哈的人生  阅读(743)  评论(0编辑  收藏  举报