Get BLOB from the BFILE Column in Oracle

In Oracle, the BFILE column is a locator or reference for the external file. It has the directory and filename information. Here I am giving an example of PL/SQL code to get BLOB from the BFILE locator column in Oracle.

PL/SQL Procedure Example - Get BLOB from BFILE Column

Declare
  l_bfile  BFILE;
  l_blob   BLOB;

  l_dest_offset INTEGER := 1;
  l_src_offset  INTEGER := 1;
BEGIN

  Select your_bfile_column into l_bfile from yourTable
    where yourCondition;
  DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
  
  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;

The variable l_blob is containing the BLOB extracted from the BFILE column

Get more Vinish.dev tutorials on Google

See my articles more often when you search Google.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted