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!

base64 decoding a clob (>32K)

570847Apr 5 2007 — edited Apr 5 2007
Hi,

Does anyone have an example or procedure of how to convert a base64-encoded clob into a Blob.
The problem I have is that the encoded data is >32K and I have to decode it in chunks.

I tried with the following test script:


declare
-- Local variables here
i integer;
l_xml sys.xmltype;


amountVal integer:=32760;
amount integer:= amountVal;
offset integer := 1;
buffer varchar2(32767);
bufferRaw raw(32767);

begin
-- Test statements here
select inhoud
into :l_clob
from test2 t
where t.id = 2;

DBMS_LOB.createTemporary( :res, TRUE );
LOOP
begin
DBMS_LOB.read(:l_clob,amount,offset,buffer);
offset:=offset + amount;
bufferRaw:=utl_raw.cast_to_raw(buffer);
bufferRaw:=utl_encode.base64_decode(bufferRaw);
dbms_lob.writeappend(:res,utl_raw.length(bufferRaw),bufferRaw);
if(amount<amountVal) then
exit;
end if;
exception
when NO_DATA_FOUND then
dbms_output.put_line('NO_DATA_FOUND');
exit;
end;
end loop;
end;

I do get a result, but it doens't make any sense. When I try to open the result width Acrobat Reader I get an error. (file has been damaged)
(The encoded data is a large pdf > 1Mb)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2007
Added on Apr 5 2007
3 comments
8,520 views