Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

understanding of this blob code

user13328581Jun 19 2019 — edited Jun 26 2019

Hello expert;

I have the following sample code below

DECLARE

  l_bfile BFILE;

  l_blob BLOB;

  l_dest_offset INTEGER := 1;

  l_src_offset INTEGER := 1;

BEGIN

  INSERT INTO tab1 (id, blob_data)

  VALUES (1, empty_blob())

  RETURN blob_data INTO l_blob;

  l_bfile := BFILENAME('BLOB_DIR', 'MyImage.gif');

  DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);

  -- loadfromfile deprecated.

  -- DBMS_LOB.loadfromfile(l_blob, l_bfile, DBMS_LOB.getlength(l_bfile));

  DBMS_LOB.loadblobfromfile (

  dest_lob => l_blob,

  src_bfile => l_bfile,

  amount => DBMS_LOB.lobmaxsize,

  dest_offset => l_dest_offset,

  src_offset => l_src_offset);

  DBMS_LOB.fileclose(l_bfile);

  COMMIT;

END;

/

it was gotten from the following link below. My question is based on the insert statement in the code. The code is meant to import file into a blob datatype and insert it into the table.

Question

Why is the insert statement at the beginning of the process? Shouldn't the insert statement be at the end, Hence my thought process is

1. saving the file into a blob variable and then using that variable in the insert statement at the end to enter the blob into a table

https://oracle-base.com/articles/8i/import-blob

This post has been answered by Billy Verreynne on Jun 20 2019
Jump to Answer
Comments
Post Details
Added on Jun 19 2019
7 comments
556 views