home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

13.4 Opening and Closing 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.


Previous: 13.3 Creating and Checking Existence of Files Advanced Oracle PL/SQL Programming with Packages Next: 13.5 Reading From a File
13.3 Creating and Checking Existence of Files Book Index 13.5 Reading From a File

The Oracle Library Navigation

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

Library Home Oracle PL/SQL Programming, 2nd. Ed. Guide to Oracle 8i Features Oracle Built-in Packages Advanced PL/SQL Programming with Packages Oracle Web Applications Oracle PL/SQL Language Pocket Reference Oracle PL/SQL Built-ins Pocket Reference










??????????????@Mail.ru