Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LISTAGG function: "result of string concatenation is too long"

Tags:

sql

oracle

I'm using Oracle SQL developer version 3.0.04. I attempted to use the function LISTAGG to group the data together..

    CREATE TABLE FINAL_LOG AS     SELECT SESSION_DT, C_IP, CS_USER_AGENT,     listagg(WEB_LINK, ' ')         WITHIN GROUP(ORDER BY C_IP, CS_USER_AGENT) "WEB_LINKS"         FROM webviews         GROUP BY C_IP, CS_USER_AGENT, SESSION_DT         ORDER BY SESSION_DT 

However, I keep getting the error,

SQL Error: ORA-01489: result of string concatenation is too long 

I'm pretty sure that the output may be more than 4000, since the WEB_LINK mentioned here is a concatenated value of url stem and url query.

Is there any way to go around it or is there any other alternative?

like image 857
user1874311 Avatar asked Dec 10 '12 04:12

user1874311


People also ask

What is the maximum length of Listagg in Oracle?

The results of listagg are constrained to the max size of VARCHAR2(4000).

What is the use of Listagg in SQL?

LISTAGG function in DBMS is used to aggregate strings from data in columns in a database table. It makes it very easy to concatenate strings. It is similar to concatenation but uses grouping. The speciality about this function is that, it also allows to order the elements in the concatenated list.


1 Answers

SELECT RTRIM(XMLAGG(XMLELEMENT(E,colname,',').EXTRACT('//text()') ORDER BY colname).GetClobVal(),',') AS LIST FROM tablename; 

This will return a clob value, so no limit on rows.

like image 142
Ankur Bhutani Avatar answered Sep 21 '22 04:09

Ankur Bhutani