Home > Database > Mysql Tutorial > How to Handle the 'ORA-01489' Error When Using LISTAGG in Oracle SQL?

How to Handle the 'ORA-01489' Error When Using LISTAGG in Oracle SQL?

DDD
Release: 2025-01-18 17:06:09
Original
526 people have browsed it

How to Handle the

Cleverly solve the Oracle LISTAGG function string too long error

In Oracle SQL Developer, when using the LISTAGG function to aggregate data, you may encounter the "ORA-01489: result of string concatenation is too long" error. This error occurs when the concatenated output exceeds an internal limit (usually 4000 characters).

To work around this limitation, the XMLAGG function can be used as an alternative. This function allows aggregation of data into an XML document, thereby bypassing character restrictions.

<code class="language-sql">SELECT RTRIM(XMLAGG(XMLELEMENT(E,colname,',').EXTRACT('//text()') ORDER BY colname).GetClobVal(),',') AS LIST
FROM tablename;</code>
Copy after login

This query uses the XMLAGG function to aggregate the values ​​of the specified column (colname) into an XML document. Then, use the GetClobVal() method to convert the XML document to the CLOB data type, thereby removing the character limit.

The final output is a comma-separated string of aggregate values ​​stored as CLOB values, allowing processing of large join outputs.

The above is the detailed content of How to Handle the 'ORA-01489' Error When Using LISTAGG in Oracle SQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template