Tuesday, 22 March 2022

To overcome the listagg issue ORA-01489: result of string concatenation is too long Use XMLagg instead of listagg

If you using listagg sometimes we will face the error "ORA-01489: result of string concatenation is too long"

Then you can modify your query with below sample

SELECT replace(dbms_lob.substr( rtrim(XMLAgg( XMLElement(a, ',',your_data_column) order by your_data_column ).getClobVal()),3999,1),',','') alias_name from table_name


Example: SELECT replace(dbms_lob.substr( rtrim(XMLAgg( XMLElement(a, ',',info) order by info ).getClobVal()),3999,1),'
,','') combined_info from bab



For more query please leave your comments