Now that you are aware of the way that UTL_FILE works, let's look at how PLVfile makes it easier to use the builtin package.
First of all, rather than insist that you separate out the file location from the file name to open and manipulate files, PLVfile provides a set of programs to make it easier to specify files. These programs are discussed below.
Each operating system has a delimiter that it uses to separate out directories and subdirectories, as well as separating directories from file names. Since PLVfile allows you to specify a file name as a single string (directory and file name combined), it needs to know about the operating system delimiter.
PROCEDURE set_delim (delim_in IN VARCHAR2);
You can find out the current operating system delimiter by calling the delim function:
The PLVfile package offers two predefined delimiters for UNIX and DOS as shown:
The default, initial setting for the OS delimiter is the UNIX delimiter: "/".
PLVfile maintains a current directory so that you do not have to continually specify a directory if you are always working in the same area on disk. To set the current directory, call the set_dir procedure. To determine the current setting for the directory, call the dir function. The headers for these programs are:
The following call to set_dir sets the default directory to a path in DOS:
SQL> exec PLVfile.set_dir ('c:\orawin\oe_app');
NOTE: If you do not call PLVfile.set_dir before passing in file names for reading and writing, there is a very good chance that your efforts to use PLVfile will be very frustrating. You will get errors that are difficult to understand, since you know your file exists. One way to minimize the frustration is to place a call to PLVfile.set_dir in your login.sql script.
Notice that I do not include a terminating backslash in the string. That "final" delimiter is needed when attaching the directory to the file name, but is neither needed nor legitimate for specifying a directory. In fact, if you include a final delimiter, PLVfile will strip it from the string, as shown below:
PROCEDURE set_dir (dir_in IN VARCHAR2) IS BEGIN v_dir := RTRIM (dir_in, v_delim); END;
PROCEDURE parse_name (file_in IN VARCHAR2, loc_out IN OUT VARCHAR2, name_out IN OUT VARCHAR2);
where file_in is the full file specification (location, name, and extension). The loc_out argument receives just the directory, while the name_out argument receives the name and extension. It relies on the operating system delimiter you assigned with a call to set_dir in order to find the start of the file name.
If the string you pass to parse_name does not have a directory prefixed on the file name, PLVfile will return the default directory as the location.
The following table shows how parse_name parses and returns values:
File Location Returned
File Name Returned
This procedure is used extensively inside PLVfile (see Section 13.4, "Opening and Closing Files" for an example of how parse_name is used to overload several different versions of fopen). You can, however, also call parse_name directly in your own application. Just make sure that you have set the OS delimiter before you use parse_name.
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.