This question already has an answer here:
Created one view within which one field(of 6) is a concatenation of two fields from the source table. Created a second view that uses listagg to potentially combine the results of the concatenation. Using this two step operation correctly returns the listagg concatenation of the two fields from the source table.
When I try to create one view that will both produce the concatenation and the listagg, I get the oracle error ora-01489 Result of string concatenation is too long.
As a test, I selected max(length(concatenated field) and that returned 837. So the stated error is in error, it seems.
So it must be in the syntax. I have tried rtrim, trim and even substr, but cannot get the view statement to both compile listagg(concatenation) and return data.
That I am able to develop the two views that correctly return the data suggests I have the basic syntax down, but the task of combining the concatenation with the listagg function I have not been able to figure out.
In a separate situation, I have been able to combine the concatenation with the listagg function in one statement:
LISTAGG (STATEMENTS || ' - ' || BIRTH_DATE, '; ')
WITHIN GROUP (ORDER BY STATEMENTS || ' - ' || BIRTH_DATE)
AS GROWING_UP
This syntax correctly returns the desired data.........
But in the situation described above, similar syntax creates the Ora-01489 error.
Knowing that at times Oracle errors can be misleading, I am wondering if any onboard experts might know of any reason other than that stated that Oracle might throw this error?
LISTAGG ((NUMBER || '-' || text), ',') WITHIN GROUP (ORDER BY (NUMBER || '-' || text))
AS
restrictions FROM source
returns the error
You are exceeding the SQL limit of 4000 bytes which applies to
LISTAGG
as well.As a workaround, you could use XMLAGG.
For example,
If you want to concatenate multiple columns which itself have 4000 bytes, then you can concatenate the XMLAGG output of each column to avoid the SQL limit of 4000 bytes.
For example,