FUNCTION fcreate (loc_in IN VARCHAR2, file_in IN VARCHAR2, line_in IN VARCHAR2) RETURN UTL_FILE.FILE_TYPE; FUNCTION fcreate (file_in IN VARCHAR2, line_in IN VARCHAR2 := NULL) RETURN UTL_FILE.FILE_TYPE; PROCEDURE fcreate (loc_in IN VARCHAR2, file_in IN VARCHAR2, line_in IN VARCHAR2); PROCEDURE fcreate (file_in IN VARCHAR2, line_in IN VARCHAR2 := NULL);
In versions of fcreate with three arguments, you provide the location, name, and single line to be deposited in the file. Notice that all three values are required. In versions of fcreate with two arguments, you provide the file specification (location and name combined, or just the name, in which case the default directory will be applied).
Notice that the overloading is not only among different parameter lists, but even different program types. I will explain this approach to overloading in PLVfile in this section; you will see it repeatedly throughout the package.
The overloading of fcreate achieves two objectives:
It allows the developer to either obtain the handle to the newly created file (the function versions) or ignore that file handle entirely (the procedure versions). You'll want to retrieve the handle if you plan to perform other actions on that file. If you only want to create the file and then move on to other business, it will be easier and more intuitive to use the procedure versions.
It allows the developer to provide the location and name separately (UTL_FILE style) or specify a single, combined string. The three-argument version requires all entries. The two-argument version allows you provide just a name; if you do not specify a line, it places the following default substitution line in the file:
When you call fcreate, it "initializes" a file to the line you provide (or the default line value) and then it closes the file if you have called the procedure version of fcreate. On the other hand, if you have called the fcreate function, PLVfile returns the handle to the file and then keeps the file open.
Perhaps you only want to create a file if it already exists. PLVfile offers the fexists function to provide you with this information. The headers for this overloaded function are:
You can provide separate locations and file names, or simply pass in the single string with combined information. The function returns TRUE if the file can be opened for read-only access successfully. If the file is already open, this function will return FALSE -- so use fexists with care.
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.