Da de linkede svar i kommentaren ikke giver min smag af løsning, sender jeg det alligevel.
Jeg bruger kun table_b
med dummy-data for at vise konceptet, kan du nemt tilføje dit join osv.:
with table_b as ( -- dummy data
select 'name'||mod(level,3) name
,mod(level,3) id
from dual
connect by level < 10
union all
select 'name'||mod(level,2) name
,mod(level,3) id
from dual
connect by level < 10
)
select id
,RTRIM (
XMLAGG (
XMLELEMENT (E,XMLATTRIBUTES (name|| ',' AS "Seg")
)
ORDER BY name ASC
).EXTRACT ('./E[not(@Seg = preceding-sibling::E/@Seg)]/@Seg'),
','
) AS "Product Name"
,LISTAGG(b.name, ',') WITHIN GROUP (ORDER BY b.name) AS "Product Name with dups"
from table_b b
group by id;
(Idéen er taget fra https://forums.oracle.com/forums/thread.jspa?messageID=9634767&tstart=0#9943367)