Re: Forms 6i - loading a binary file into a BLOB

From: Eric Wright <ewright_at_nc.rr.com>
Date: 9 Jan 2002 13:26:04 -0800
Message-ID: <221fdb16.0201091326.7b27f80c_at_posting.google.com>


I've only been working with Blobs for a little while, but from what I've seen, the dbms_lob package works well. However, this will only work on code from the database server.

I'd suggest creating a package on the server, then calling a member function of that package in your on-insert form trigger.

Here is a sample of how to handle the load...

create table blob_test (id number not null primary key, blob_file blob);

create or replace directory my_files as 'C:\My Documents';

create or replace procedure blob_ins(p_id in number, p_filename in varchar2) as

  l_bfile     bfile;
  l_blob      blob;

begin
  insert into blob_test(p_id, empty_blob())   returning blob_file into l_blob;

  l_bfile := bfilename('MY_FILES', p_filename);

  dbms_lob.fileopen(l_bfile);
  dbms_lob.loadfromfile(l_blob, l_bfile, dbms_lob.getlength(l_bfile));
  dbms_lob.fileclose(l_bfile);

  commit;
  return;
end blob_ins;
/

The directory you created (my_files) is a database pointer to a folder or directory on the DB server that contains the file in question. When it gets used in the bfilename call, it's been automatically upper-cased, like other objects (tables, views, etc).

The returning clause essentially creates a referential link between the local variable l_blob and the current record of the table blob_test. Modifying the value in l_blob automatically updates the current record, so no additional updates are necessary.

Good luck.
Eric

macvl2000_at_yahoo.it (Macvl2000) wrote in message news:<dfb206b6.0112281157.7a943e7d_at_posting.google.com>...
> I am developing a Forms 6i client/server application in a Win2k environment.
> Upon request by the user, the application must read a binary file
> (say, a Word document or an Excel spreadsheet) stored in the filesystem of
> the client PC and save it into a BLOB column of a database table.
>
> I tried to use ORA_FFI for loading the file but I found no way to return
> a buffer containing ASCII 0's into a PLSQL varchar2 variable, so this method
> does not seem useful.
>
> The question is: what is the best way to load a file into a BLOB using Forms
> (d2kutil, user exit, ....)?
Received on Wed Jan 09 2002 - 22:26:04 CET

Original text of this message