Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Probs - reading to/from - PDF to BLOB...
Howdy !
Via Tom Kyte's site - I found two routines for reading/writing - a PDF file to/from database. See below.
Question I've tried to read/write the same PDF and GIF - file - but both times the output file - which should be identical to the input file - ended up different/corrupted?
Using Xp, 10g - same for in/out.............
Any suggestions?
Rgds, Henrik
Listing 1)
CREATE OR REPLACE procedure ins_file_in_blob is
l_blob blob;
l_bfile bfile;
begin
insert into files_org (id, content) values ( 1, empty_blob() )
returning content into l_blob;
l_bfile := bfilename( 'MY_FILES', 'input.gif');
dbms_lob.fileopen( l_bfile );
dbms_output.put_line('Length of file : ' || dbms_lob.getlength( l_bfile ));
dbms_lob.loadfromfile( l_blob, l_bfile, dbms_lob.getlength( l_bfile ) );
dbms_lob.fileclose( l_bfile );
end;
/
Listing 2)
create or replace procedure extract_blob_to_pdf is
vblob blob;
vstart number:=1;
bytelen number := 32000;
len number;
my_vr raw(32000);
l_output utl_file.file_type;
p_file varchar2(30) default 'output.pdf';
begin
l_output := utl_file.fopen('MY_FILES', p_file, 'w', 32760);
for l_cur in (SELECT CONTENT from files_org where id = 1 and rownum = 1)
loop
len := DBMS_LOB.GETLENGTH(l_cur.content);
vblob := l_cur.content ;
dbms_output.put_line('Length of the Column : ' || to_char(len));
vstart := 1;
while (vstart < len) loop -- loop till entire data is fetched
dbms_output.put_line('vstart : ' || to_char(vstart));
DBMS_LOB.READ(vblob,bytelen,vstart,my_vr);
utl_file.put_raw(l_output,my_vr);
utl_file.fflush(l_output);
vstart := vstart + bytelen ;
end loop;
utl_file.fclose(l_output);
end loop;
end; Received on Sat Mar 26 2005 - 21:05:18 CST
![]() |
![]() |