I have a table in oracle with a BLOB
column, that can store XMLs and as well XMLs
zipped. These are requirements from the customer and can't be changed. The tables will be created and I have to read and work with some information inside the BLOBs
.
I have researched and any of the unclear solutions were clear or worked for me.
The problem I am facing is that to INSERT
XML
plain data bigger than 2000 bytes
with utl_raw.cast_to_raw
using DBeaver
as Database Manager. I received the message:
SQL Error [6502] [65000]: ORA-06502: PL/SQL: numeric or value error: raw variable length too long ORA-06512: at "SYS.UTL_RAW", line 224
java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: raw variable length too long
ORA-06512: at "SYS.UTL_RAW", line 224
Problems
UTL_RAW
can't be longer than 2000 bytes
4000 bytes
for BLOBs
in OracleWhat could I do for those cases?
From 12c onwards you can increase the limit on the database to 32767 bytes, the same as varchar2 in PL code. Prior to 12c you have no choice but to use CLOB for more than 4000 bytes of character data.
For strings greater than 4000 use a CLOB. you can use CLOB column.
A BLOB (binary large object) is a varying-length binary string that can be up to 2,147,483,647 characters long.
For starters, you need to understand what LOBs are. They are "large data", possibly larger than any other data types in Oracle. They are like regular files on a filesystem. In order to write to a file on a filesytem, you'll have to
More or less the same is true for LOBs. In your table, a LOB (CLOB/BLOB/NCLOB) column is just a pointer/reference to another place on your disk storage holding the actual data. In standard Oracle terms, the pointer is called "LOB locator". You need to
In PL/SQL it could look like this:
-- create table blob_test(id number, b blob);
declare
v_b blob;
aaa raw(32767);
longLine varchar2(32767);
begin
longLine := LPAD('aaaa', 32767,'x');
aaa := UTL_RAW.CAST_TO_RAW(longLine);
insert into blob_test values(1,empty_blob()) returning b into v_b;
dbms_lob.open(v_b,dbms_lob.lob_readwrite);
dbms_lob.writeappend(v_b,UTL_RAW.LENGTH (aaa) ,aaa);
dbms_lob.close(LOB_LOC=>v_b);
commit;
end;
An explanation:
insert into blob_test values(1,empty_blob()) returning b into v_b;
dbms_lob.open(v_b,dbms_lob.lob_readwrite);
empty_blob()
call in the insert
.dbms_lob.writeappend()
, appending only a single chunk aaa
of length utl_raw.length(aaa)
(maximum of 32767) into the LOB v_b
dbms_lob.close(LOB_LOC=>v_b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With