Home >Database >Mysql Tutorial >How to Handle Oracle's ORA-01489: 'Result of String Concatenation is Too Long'?
Error Handling in Oracle: ORA-01489: Result of String Concatenation is Too Long
Oracle's ORA-01489 error occurs when the result of a string concatenation exceeds the maximum allowed length. However, this error can sometimes be misleading.
Case 1: Exceeding the SQL Limit
The default SQL limit for string concatenation is 4000 bytes. Concatenating strings beyond this limit triggers the ORA-01489 error. This applies to the LISTAGG function as well.
Workaround:
Use XMLAGG instead of LISTAGG, as it allows for larger concatenated strings.
Case 2: Concatenating Multiple Long Columns
If you are concatenating multiple columns that each exceed 4000 bytes, the result can still trigger the error.
Workaround:
Concatenate the XMLAGG output of each column to avoid the SQL limit. For example:
SELECT rtrim(xmlagg(XMLELEMENT(e,col1,',').EXTRACT('//text()') ).GetClobVal(), ',') || rtrim(xmlagg(XMLELEMENT(e,col2,',').EXTRACT('//text()') ).GetClobVal(), ',') AS very_long_text FROM DATA GROUP BY ID ORDER BY ID;
The above is the detailed content of How to Handle Oracle's ORA-01489: 'Result of String Concatenation is Too Long'?. For more information, please follow other related articles on the PHP Chinese website!