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
查询结果: