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 encode

user12223156Nov 19 2012 — edited Nov 19 2012
Hi

I want to encode (Base64) the "PNG" image. It is working fine with small size image,When i'm giving the large size "PNG" image getting Error

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

DECLARE
p_dir varchar2(100):='/test/bala_test/';
p_file varchar2(100):= 'test_img.PNG';
dest_dir varchar2(100):='/test/bala_test/';
dest_file varchar2(100):='test_image.html';
dest_handle UTL_FILE.file_type;
p_clob CLOB;
l_bfile BFILE;
l_step PLS_INTEGER := 24573;

BEGIN
dbms_output.put_line('Encoding starts');
l_bfile := BFILENAME('BFILE_DIR', p_file);

dbms_output.put_line('File is going to open');
DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);

FOR i IN 0 .. TRUNC((DBMS_LOB.getlength(l_bfile) - 1 )/l_step) LOOP
dbms_output.put_line('Inside encodeing');
p_clob := p_clob || UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(DBMS_LOB.substr(l_bfile, l_step, i * l_step + 1)));
END LOOP;

p_clob:= '<img src="data:image/png;base64,'||p_clob||'" width="32" height="32">';
dest_handle := UTL_FILE.fopen(p_dir, dest_file, 'w', 32767);
UTL_FILE.put(dest_handle, p_clob);
DBMS_LOB.fileclose(l_bfile);

dbms_output.put_line('Encoding ends successfully');
exception
when others then
dbms_output.put_line('Error : '||SQLERRM);
end;
/


Kindly Assist me on this.

Thanks inadvance.

Regards
Balasundaram
This post has been answered by Solomon Yakobson on Nov 19 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2012
Added on Nov 19 2012
5 comments
2,613 views