I’m using Oracle 11g r2 and I need to concatenate strings (VARCHAR2, 300) from multiple rows. I’m using LISTAGG which works great until the concatenated string reaches the limit. At that point I receive a ORA-01489: result of string concatenation is too long.
In the end, I only want the first 4000 chars of the concatenated string. How I get there doesn’t matter. I will accept inefficient solutions.
Here’s my query:
SELECT LISTAGG(T.NAME, ' ') WITHIN GROUP (ORDER BY NULL)
FROM T
You can either use the built-in (but deprecated) STRAGG function
(please note that distinct seems to be necessary to avoid duplicates)
or define your own aggregation function / type:
and use it like this:
I believe this approach was orginally proposed by Tom Kyte (at least, that’s where I got it from – Asktom: StringAgg