Kombination af xmlagg og xQuery, det er ikke nemt.
select xmlquery('distinct-values(//text())' passing x returning content).getclobVal(),data_type from (
select xmlelement(root, xmlagg(XMLELEMENT(e,table_name,','))) x ,data_type
from user_tab_cols where data_type in ('VARCHAR2','NUMBER')
group by data_type
)
Og til dit formål burde det se sådan ud
select
app, key_event,
xmlquery('distinct-values(//text())' passing xmldoc returning content).getclobVal()
from
(select
t2.app,
coalesce(max(case when language = 2 then description end),
max(case when language = 12 then description end),
max(case when language = 27 then description end),
'NULL') key_event,
XMLELEMENT(root, xmlagg(XMLELEMENT(e, description, ','))
) xmldoc
from
table2 t2
left join
table1 t1 on t1.app = t2.app
group by
trans, t2.app
order by trans);
hvis du vil dekomponere denne forespørgsel, vil du se, hvordan den fungerer.
xquery distinct-values syntaks