Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-40478 when returning large json into clob in Oracle 19c

Tags:

json

oracle

clob

In Oracle 19c I created the table:

create table SAMPLE_TABLE (
id NUMBER not null,
display_name  NVARCHAR2(4000), )

When I run the script:

declare    
   i integer;   
   p_tmp_clob clob;
 begin   
   select JSON_ARRAYAGG(JSON_OBJECT(t.* )) into p_tmp_clob from SAMPLE_TABLE t;
end; 

I am getting the following ORA-40478 exception. ORA-40478: output value too large (maximum: 4000)

like image 938
Goxy Avatar asked Oct 11 '19 11:10

Goxy


1 Answers

You need to tell the function to return a CLOB, not a varchar:

It might be necessary for JSON_ARRAYAGG as well (or maybe only there - I can't test it right now)

declare    
   i integer;   
   p_tmp_clob clob;
 begin   
   select JSON_ARRAYAGG(JSON_OBJECT(t.* RETURNING CLOB) RETURNING CLOB) 
     into p_tmp_clob 
   from SAMPLE_TABLE t;
end; 
like image 60
a_horse_with_no_name Avatar answered Sep 20 '22 20:09

a_horse_with_no_name