Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

json query for clob column error

User_8Q7DSSep 12 2021 — edited Sep 12 2021

1.txt (177.81 KB)DB Version: 12.2.0.1.0
Hi,
i have attached xml. when i am trying to convert to json, i am getting error
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 123564, maximum: 4000).
It is for the file_data column. Appreciate your assistance

DECLARE


  l_json_body        CLOB;
       
  CURSOR xmldata IS
    SELECT *
      FROM xml_tab;

BEGIN


FOR rec in xmldata
  loop


SELECT json_arrayagg(json_object(
                                      'document_id'                 VALUE   document_id     
                                      ,'file_category'              VALUE   file_category
                                      ,'file_type'                  VALUE   file_type
                                      ,'content_type'               VALUE   content_type
                                      ,'file_data'                  VALUE   file_data                            
                                      )) 
                                      INTO   l_json_body
                                    FROM xmltable('/attachments/attachment' passing(rec.xml_data) 
                                               columns 
                                                 document_id           NUMBER             path 'document_id'
                                                 ,file_category        VARCHAR2(240)      path 'file_category'
                                                 ,file_type            VARCHAR2(240)      path 'file_type'
                                                 ,content_type         VARCHAR2(240)      path 'content_type'
                                                 ,file_data            CLOB               path 'file_data'
                                                 );
                                                 
	end loop;                                                 
END;                                                 
This post has been answered by Solomon Yakobson on Sep 12 2021
Jump to Answer
Comments
Post Details
Added on Sep 12 2021
9 comments
1,244 views