Problem is as follows: I need a concatenated list of names somewhere in my query. This is easy enough to accomplish with LISTAGG, but the result may become longer than 4000 characters, so I decided to use XMLAGG. Query goes like this:
SELECT
id_flurstueck,
REGEXP_REPLACE(RTRIM(EXTRACT(XMLAGG(XMLELEMENT(e, bezeichner || '; ') ORDER BY bezeichner), '/E/text()').getclobval(), '; '),
'([^;]*)(; \1)+($|;)',
'\1\3') AS eigentuemer
FROM
mv_alkis_eigentuemer
GROUP BY
id_flurstueck ;
mv_alkis_eigentuemer is a materialized view and the query gives me the expected answer. Slow - but working.
But I need those names in a longer query, and so I join on that SELECT.
SELECT
ae.eigentuemer,
manyOtherAttributes
FROM
myTable t LEFT JOIN (
SELECT
id_flurstueck,
REGEXP_REPLACE(RTRIM(EXTRACT(XMLAGG(XMLELEMENT(e, bezeichner || '; ') ORDER BY bezeichner), '/E/text()').getclobval(), '; '),
'([^;]*)(; \1)+($|;)',
'\1\3') AS eigentuemer
FROM
mv_alkis_eigentuemer
GROUP BY
id_flurstueck
) ae
ON t.id_flurstueck = ae.id_flurstueck ;
Unfortunately this results in
ORA-00932: inconsistent datatypes: - expected, CLOB received
Same result if I use the query inline as a correlated subquery.
Any ideas, how to overcome this?
Database is Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production.
Thanks in advance, Bernd