oracle 每个LISTAGG值的连接

rta7y2nd  于 2023-03-17  发布在  Oracle
关注(0)|答案(1)|浏览(105)

是否可以为每个LISTAGG值指定另一个CONCAT值?
查询示例:

SELECT
table1.id AS ID,
LISTAGG(table2.object_id,';') WITHIN GROUP (ORDER BY table2.object_id) AS my_list 
FROM 
table1
JOIN table2
ON table1.id = table2.tbl1_id
GROUP BY table1.id

样本输出:

ID     MY_LIST
25     123;456;123;857

所需输出:

ID     MY_LIST
25     123 = 4;456 = 6;857 = 2
vsikbqxv

vsikbqxv1#

也许它会工作,也许它不会,这取决于结果列的长度是否小于4000个字符...我认为下面的代码将产生您所需要的。

SELECT
       table1.id AS ID,
       LISTAGG(table2.object_id||'='||table2.id,';') WITHIN GROUP (ORDER BY table2.object_id) AS my_list 
FROM table1
JOIN table2 ON table1.id = table2.tbl1_id
GROUP BY table1.id

相关问题