BASE64 (PDF) CLOB to BLOB
940363May 29 2012 — edited Jun 4 2012Hello everybody! I have to convert a BASE64 representation of a PDF file to BLOB. I found one example on the Internet but there is something wrong with it and I can't figure it out.
create or replace function decode_base64(p_clob_in in clob) return blob is
v_blob blob;
v_offset integer;
v_buffer_varchar varchar2(32000);
v_buffer_raw raw(32000);
v_buffer_size binary_integer := 32000;
begin
if p_clob_in is null then
return null;
end if;
dbms_lob.CREATETEMPORARY(v_blob, true);
v_offset := 1;
FOR i IN 1..CEIL(dbms_lob.GETLENGTH(p_clob_in) / v_buffer_size)
loop
dbms_lob.READ(p_clob_in, v_buffer_size, v_offset, v_buffer_varchar);
v_buffer_raw := utl_encode.BASE64_DECODE(utl_raw.CAST_TO_RAW(v_buffer_varchar));*
dbms_lob.WRITEAPPEND(v_blob, utl_raw.LENGTH(v_buffer_raw), v_buffer_raw);
v_offset := v_offset v_buffer_size;+
end loop;
return v_blob;
end decode_base64;
The above procedure should work with files of any size (since there is a loop), but it only works when the PDF is smaller than 32 KB.