Get BLOB from the BFILE Column in Oracle

Get BLOB from the BFILE Column in Oracle

  • PLSQL
  • 1 min read

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