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!

Received ORA-06502: PL/SQL: numeric or value error: raw variable length too long

sect55May 18 2021

I'm not very familiar with BLOB and RAW Strings.
I am trying to convert BLOB to Base64 string and received ORA-06502: PL/SQL: numeric or value error: raw variable length too long error.
I am using the following function:


 FUNCTION CONVERT_BLOB_TO_BASE64(
                          P_BLOB BLOB
                         )
    RETURN CLOB
    IS
        V_CLOB CLOB := null;
        V_CHUNK_SIZE PLS_INTEGER := 24000;
    BEGIN
    apex_debug.info ('*** In convert_to_base64');
        FOR V_I IN 0..TRUNC((DBMS_LOB.GETLENGTH(P_BLOB) - 1 ) / V_CHUNK_SIZE) LOOP
        apex_debug.info ('*** v_i = %s', to_char(v_i));
          V_CLOB := V_CLOB || UTL_RAW.CAST_TO_VARCHAR2(
                                                       UTL_ENCODE.BASE64_ENCODE(
                                                                                DBMS_LOB.SUBSTR(
                                                                                                P_BLOB,
                                                                                                V_CHUNK_SIZE,
                                                                                                V_I * V_CHUNK_SIZE + 1
                                                                                               )
                                                                   )
                                         );
        apex_debug.info ('*** *** v_clob= %s',v_clob);          
        END LOOP;
        RETURN V_CLOB;
END CONVERT_BLOB_TO_BASE64;

I am attaching the BLOB file (a PDF file)
Please help.
Sample Exh A document.pdf (60.44 KB)Thank you,
Robert

This post has been answered by Paulzip on May 18 2021
Jump to Answer
Comments
Post Details
Added on May 18 2021
3 comments
4,688 views