Pages

Tuesday, November 25, 2014

Data Convertion from a FILE(jpeg,gif,pdf,doc,txt etc.) to BLOB in ORACLE

paid surveys

Compile below procedure:

CREATE OR REPLACE Procedure Dpr_fileToBlob(Fname in VARCHAR2, Fdir in VARCHAR2, OutBlob out BLOB)
IS

fblob BLOB;
theBFile BFILE;

Bsrc_offset NUMBER :=1;
Bdest_offset NUMBER :=1;

BEGIN

dbms_lob.createtemporary(fblob,FALSE,DBMS_LOB.SESSION);
theBFile := BFileName(Fdir,Fname);
dbms_lob.fileOpen(theBFile);

dbms_lob.loadblobfromfile(dest_lob => fblob ,
                                              src_bfile =>theBFile ,
                                             amount => dbms_lob.getLength(theBFile),
                                             dest_offset => Bdest_offset,
                                             src_offset => Bsrc_offset);

dbms_lob.fileClose(theBFile);
OutBlob := fblob;

End;
/

***Now execute below PLSQL block to show your desired output:

declare
  v_blob blob;
begin
  Dpr_fileToBlob(Fname   => 'File_Name.ext',
                 Fdir    => 'Database_Directory_Name',
                 OutBlob => v_blob);
  dbms_output.out_line(dbms_lob.getlength(v_blob));
end;
 
paid surveys

No comments:

Post a Comment