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

Home
Oracle PL / SQL
1.Aggregate Functions
2.Analytical Functions
3.Char Functions
4.Constraints
5.Conversion Functions
6.Cursor
7.Data Type
8.Date Timezone
9.Hierarchical Query
10.Index
11.Insert Delete Update
12.Large Objects
13.Numeric Math Functions
14.Object Oriented Database
15.PL SQL
16.Regular Expressions
17.Report Column Page
18.Result Set
19.Select Query
20.Sequence
21.SQL Plus
22.Stored Procedure Function
23.Subquery
24.System Packages
25.System Tables Views
26.Table
27.Table Joins
28.Trigger
29.User Previliege
30.View
31.XML
Oracle PL / SQL » Large Objects » bfile 
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 = 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 = 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.