13.4 Opening and Closing Files

Chapter 13
PLVfile: Reading and Writing Operating System Files
 

PLVfile offers its own fopen and fclose programs to open and close operating system files (UTL_FILE has programs of the same names). The fopen module is overloaded as shown below:

PROCEDURE fopen     (loc_in IN VARCHAR2, file_in IN VARCHAR2, mode_in IN VARCHAR2); PROCEDURE fopen     (file_in IN VARCHAR2, mode_in IN VARCHAR2 := c_all); FUNCTION fopen     (file_in IN VARCHAR2, mode_in IN VARCHAR2 := c_all) RETURN UTL_FILE.FILE_TYPE;

Use the function version of fopen when you want to retrieve and use the file handle. Otherwise, you can simply call either of the procedure versions to open the file and not worry about declaring a file handle.

The fclose and fclose_all procedures may be used to close one or all files. Their headers are:

PROCEDURE fclose (file_in IN UTL_FILE.FILE_TYPE); PROCEDURE fclose_all;

Notice that there is no overloading of the fclose program. Until a reader or the author enhances PLVfile to maintain a PL/SQL table of opened file names and their handles, there is no way to close a file by name. The fclose_all procedure is a passthrough to UTL_FILE.FCLOSE_ALL, which shuts down any files that have been opened with the UTL_FILE.FOPEN program.

You may find it useful to include a call to fclose or, more likely, fclose_all, in the exception sections of programs that work with PLVfile. That way if your program fails during file manipulation, it will not leave a file open. If the file is left open, that could cause another, different error, the next time you try to run it.


13.3 Creating and Checking Existence of Files13.5 Reading From a File

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.



Advanced Oracle PL. SQL Programming with Packages
Advanced Oracle Pl/Sql: Programming With Packages (Nutshell Handbook)
ISBN: B00006AVR6
EAN: N/A
Year: 1995
Pages: 195
Authors: Steven Feuerstein, Debby Russell
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net