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

How to Overcome ORA-01489 Error When Using LISTAGG in Oracle SQL?

Susan Sarandon
Release: 2025-01-18 16:51:13
Original
535 people have browsed it

How to Overcome ORA-01489 Error When Using LISTAGG in Oracle SQL?

Oracle SQL LISTAGG Function and ORA-01489 Error

The LISTAGG function, useful for concatenating strings within Oracle SQL Developer, can generate the "ORA-01489: result of string concatenation is too long" error. This limitation stems from LISTAGG's output being restricted to a maximum of 4000 characters.

Solution using XMLAGG

To overcome this 4000-character limit, employ the XMLAGG function as a more flexible alternative:

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

XMLAGG returns a CLOB data type, capable of handling significantly larger string lengths, thus eliminating the ORA-01489 error. This approach effectively aggregates extensive datasets without the constraints imposed by LISTAGG.

The above is the detailed content of How to Overcome 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template