Tuesday, April 22, 2014

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

If you are using utl_raw.cast_to_raw(input_string) in a SQL, it will fail where
 input_string length  > 2000

--This will fail
select utl_raw.cast_to_raw(lpad('demo',2001,'z')) raw_str
from dual;

ORA-06502: PL/SQL: numeric or value error: raw variable length too long
ORA-06512: at "SYS.UTL_RAW", line 224

--This will work
select utl_raw.cast_to_raw(lpad('demo',2000,'z')) raw_str
from dual;


You have to write a pl/sql and handle the raw conversion outside the SQL, as shown below.

Create table t2( col1 blob);

Declare
bBlob blob;
begin
    bBlob := utl_raw.cast_to_raw(lpad('aaaa',4000,'z')) ;
    Insert into t2 values (bBlob);
 commit;
end;
/

No comments:

Post a Comment