We have a view created which has a column using a select statement to generate a LISTAGG of values.
(select LISTAGG(distinct reporters_case_id, '; ') FROM cdss_live.CASE_REPORTER@SAPP_TRANSCT_DB CR WHERE cv.case_seq = cr.case_seq ) as ALL_REPORTER_CASE_IDs,
Querying this view works fine.
As soon as we join the view (VW_QRE_TEST) to another table.
select A.SAPPHIRE_CASE_ID,
A.SAPPHIRE_CASE_VERSION,
CASE WHEN (B.SAPPHIRE_CASE_ID IS NULL OR B.SAPPHIRE_CASE_VERSION IS NULL) THEN 'Select' else null end as Action
from VW_TEST_QRE_STEP A LEFT JOIN T_PV_GLOBAL_INLINE_CASE_QC B
ON A.SAPPHIRE_CASE_ID = B.SAPPHIRE_CASE_ID AND A.SAPPHIRE_CASE_VERSION = B.SAPPHIRE_CASE_VERSION
WHERE
A.SAPPHIRE_CASE_ID = :P5_SAPPHIRE_CASE_ID;
It blows up:
ORA-01489: result of string concatenation is too long
ORA-02063: preceding line from SAPP_TRANSCT_DB
01489. 00000 - "result of string concatenation is too long"
*Cause: String concatenation result is more than the maximum size.
*Action: Make sure that the result is less than the maximum size.
Why would the listagg, which gets calculated in the view and works in isolation, suddenly blow up when joined to another table? The listagg would be performed and isolated in the context of the view on its own, not in the context of a join taking place after the view is calculated?
Querying the view in isolation for the problem record, the listagg in isolation returns NULL, which is as expected - so there is nothing to listagg anyway.
Added a FIDDLE: http://sqlfiddle.com/#!4/c8bddf/15
UPDATE: The query runs fine if I remove the WHERE clause, which is odd...
select A.SAPPHIRE_CASE_ID,
A.SAPPHIRE_CASE_VERSION,
CASE WHEN (B.SAPPHIRE_CASE_ID IS NULL OR B.SAPPHIRE_CASE_VERSION IS NULL) THEN 'Select' else null end as Action
from VW_TEST_QRE_STEP A LEFT JOIN T_PV_GLOBAL_INLINE_CASE_QC B
ON A.SAPPHIRE_CASE_ID = B.SAPPHIRE_CASE_ID AND A.SAPPHIRE_CASE_VERSION = B.SAPPHIRE_CASE_VERSION
