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.
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.
This HTML Help has been published using the chm2web software. |