BFILE File Operations : bfile « Large Objects « Oracle PL / SQL






BFILE File Operations

  
SQL>
SQL> CREATE OR REPLACE DIRECTORY books_Dir AS 'C:\BOOKS';

Directory created.

SQL>
SQL>
SQL> DECLARE
  2       v_BOOKFILE BFILE;
  3       v_DIRNAME VARCHAR2(30);
  4       v_LOCATION VARCHAR2(2000);
  5       v_FILEISOPEN INTEGER;
  6       v_FILEEXISTS INTEGER;
  7
  8  BEGIN
  9       v_BOOKFILE := BFILENAME('BOOKS_DIR','BOOK1.GIF');
 10       v_FILEISOPEN := DBMS_LOB.FILEISOPEN(v_BOOKFILE);
 11
 12       v_FILEEXISTS := DBMS_LOB.FILEEXISTS(v_BOOKFILE);
 13
 14       IF v_FILEEXISTS = 1 THEN
 15             DBMS_OUTPUT.PUT_LINE('The file exists');
 16       ELSE
 17             DBMS_OUTPUT.PUT_LINE('The file cannot be found');
 18       END IF;
 19
 20       IF v_FILEISOPEN = 1 THEN  --Determine actions if file is opened
 21             DBMS_OUTPUT.PUT_LINE('The file is open');
 22       ELSE
 23             DBMS_OUTPUT.PUT_LINE('Opening the file');
 24             DBMS_LOB.FILEOPEN(v_BOOKFILE);
 25       END IF;
 26       DBMS_LOB.FILEGETNAME(v_BOOKFILE,v_DIRNAME,v_LOCATION);
 27       DBMS_OUTPUT.PUT_LINE('The Directory Object is: ' || v_DIRNAME ||
 28            ' The File Name is: ' || v_LOCATION);
 29
 30       DBMS_LOB.FILECLOSE(v_BOOKFILE); -- Close the BFILE
 31
 32  END;
 33  /
The file cannot be found
Opening the file
DECLARE
*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
The system cannot find the path specified.
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at line 24


SQL>
SQL>
SQL> --

   
  








Related examples in the same category

1.Create the BFILE directory
2.Two locators pointing to the same file
3.Insert value to bfile column
4.BFILE Comparisons
5.Call BFILENAME to get pointer to a BFILE
6.BFILENAME function