ORA-06502: PL/SQL: 'Numeric or Value Error' When CLOB Convert to VARCHAR2 on a Multibyte Database (Doc ID 827955.1)

Last updated on JULY 05, 2017

Applies to:

PL/SQL - Version 8.1.7.4 to 11.2.0.2 [Release 8.1.7 to 11.2]
Information in this document applies to any platform.
***Checked for relevance on 02-Jan-2014***

Symptoms

On a database with multibyte characterset like AL32UTF8 specified for NLS_CHARACTERSET the following error is received when a CLOB which contains more than 8191 characters is assigned to a VARCHAR2 variable.

ORA-06502: PL/SQL: numeric or value error when CLOB convert to VARCHAR2

You can reproduce the error with the below code:

declare
     VARCHAR2_32767     VARCHAR2(32767) := NULL ;
     V_CLOB             CLOB            ;
begin
     for i in 1..32767 loop
        V_CLOB           := V_CLOB || 'A';
     end loop;
     /* The below statement fails if data in clob more than
      8191 characters in multibyte characterset environment */
    VARCHAR2_32767   := V_CLOB ; 
end;

 

Exception Stack:

declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 10


Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms