How to write a query that does something similar to MySQL's GROUP_CONCAT in Oracle?

隐身守侯 提交于 2019-11-28 14:29:29
SELECT p.pkt_nazwa AS name, wm_concat(u.us_nazwa) AS services
FROM   punkty p
JOIN   kategorie_uslug ku ON ku.pkt_id = p.pktk_1_id
JOIN   usluga u ON u.usk_1_id = ku.us_id
GROUP  BY p.pkt_nazwa
ORDER  BY p.pkt_nazwa;

wm_concat() function is present in most versions.
More about string aggregating in Oracle.

Here's an article explaining some approaches to what you're trying to do in Oracle:

http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

Note that if you're running 11g Release 2 then LISTAGG is the way to go.

Since Oracle 11.2 this has become easier using listagg()

SELECT p.pkt_nazwa AS name, 
       listagg(u.us_nazwa) WITHIN GROUP (ORDER BY u.us_nazwa) AS services
FROM punkty p
  JOIN kategorie_uslug ku ON ku.pkt_id = p.pktk_1_id
  JOIN usluga u ON u.usk_1_id = ku.us_id
GROUP BY p.pkt_nazwa
ORDER BY p.pkt_nazwa;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!