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

13.3 Creating and Checking Existence of Files

PLVfile provides a program (four overloaded versions, actually) to create a file. The headers for fcreate are the following:

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:

  1. 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.

  2. 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:

    
    
    v_subst_line VARCHAR2(200) :=
       'I make my disk light blink, therefore I am.';

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.

13.3.1 Checking a File's Existence

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:

FUNCTION 

fexists (loc_in IN VARCHAR2, file_in IN VARCHAR2)
RETURN BOOLEAN;

FUNCTION fexists (file_in IN VARCHAR2)
RETURN BOOLEAN;

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.


Previous: 13.2 Specifying the File in PLVfile Advanced Oracle PL/SQL Programming with Packages Next: 13.4 Opening and Closing Files
13.2 Specifying the File in PLVfile Book Index 13.4 Opening and Closing Files

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