Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Probs - reading to/from - PDF to BLOB...

Probs - reading to/from - PDF to BLOB...

From: Verner Jensen, Ålborg <java_at_ofir.dk>
Date: Sat, 26 Mar 2005 19:05:18 -0800
Message-ID: <qwh1e.107589$Vf.4091205@news000.worldonline.dk>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US