Re: Load a blob from file + UPDATE a record

From: Bastiaan Schaap <fake_address_at_nomail.com>
Date: Sat, 21 Jul 2001 21:51:35 GMT
Message-ID: <SVIV6.17$wU3.686_at_psinet-eu-nl>


Well..... Just to give an example:

first you have to create a directory object (create or replace directory DOCUMENT_DIR ....). This object will point to the directory where your files are...

create or replace PROCEDURE fileToBlob IS

  src_file   BFILE := bfilename('DOCUMENT_DIR','image.gif');
  dst_file   BLOB;
  lgh_file   integer;

BEGIN
  src_file := bfilename('DOCUMENT_DIR','image.gif');

  • lock the record first select bin_data into dst_file from db_image where filename = 'image' and fileext = 'gif' for update;
  • open the file dbms_lob.fileopen(src_file, dbms_lob.file_readonly);
  • determine the length of the file lgh_file := dbms_lob.getlength(src_file);
  • read file from os dbms_lob.loadfromfile(dst_file, src_file, lgh_file);
  • update your blob field update db_image set bin_data = dst_file where filename = 'image' and fileext = 'gif'; commit; dbms_lob.fileclose(src_file); EXCEPTION WHEN ACCESS_ERROR THEN dbms_output.put_line('Access Error');

  WHEN INVALID_ARGVAL THEN
    dbms_output.put_line('Invalid Argval');

  WHEN INVALID_DIRECTORY THEN
    dbms_output.put_line('Invalid Directory');

  WHEN NO_DATA_FOUND THEN
    dbms_output.put_line('No Data Found');

  WHEN NOEXIST_DIRECORY THEN
    dbms_output.put_line('Noexist Directory');

  WHEN NOPRIV_DIRECORY THEN
    dbms_output.put_line('Nopriv directory');

  WHEN OPEN_TOOMANY THEN
   dbms_output.put_line('Open Toomany');

  WHEN OPERATION_FAILED THEN
    dbms_output.put_line('Operation Failed');

  WHEN UNOPENED_FILE THEN
    dbms_output.put_line('Unopened File');

  WHEN OTHERS THEN

  • do your own stuff here....

END;
/

It's just too simple, isn't it? ;-))

HTH,

--
Bastiaan Schaap
________________________________
Error in operator: add beer


"Patrick Lefebvre" <patrick_lefebvre_at_sympatico.ca> wrote in message
news:KpBV6.32554$QE4.3160671_at_news20.bellglobal.com...

> How to load a blob from file + UPDATE a record.
>
> I know the procedure "DBMS_LOB.LOADFROMFILE()" but the tutorials are not
> really clear about that.
>
> Thx !
>
> Pat
>
>
Received on Sat Jul 21 2001 - 23:51:35 CEST

Original text of this message