Oracle9i Supplied PL/SQL Packages and Types Reference Release 1 (9.0.1) Part Number A89852-02 |
|
With the UTL_FILE
package, your PL/SQL programs can read and write operating system text files. UTL_FILE
provides a restricted version of operating system stream file I/O.
UTL_FILE
I/O capabilities are similar to standard operating system stream file I/O (OPEN
, GET
, PUT
, CLOSE
) capabilities, but with some limitations. For example, you call the FOPEN
function to return a file handle, which you use in subsequent calls to GET_LINE
or PUT
to perform stream I/O to a file. When file I/O is done, you call FCLOSE
to complete any output and free resources associated with the file.
This chapter discusses the following topics:
The PL/SQL file I/O feature is available for both client-side and server-side PL/SQL. The client implementation (text I/O) is subject to normal operating system file permission checking. However, the server implementation may be running in a privileged mode, which requires a restriction on the directories that can be accessed. Accessible directories must be specified in the instance parameter initialization file (INIT
.ORA
).
Accessible directories for the UTL_FILE
functions are specified in the initialization file using the UTL_FILE_DIR
parameter. For example:
UTL_FILE_DIR = <directory name>
If the initialization file for the instance contains the line UTL_FILE_DIR = /usr/jsmith/my_app,
then the directory /usr/jsmith/my_app
is accessible to the FOPEN
function. Note that a directory named /usr/jsmith/My_App
would not be accessible on case-sensitive operating systems.
The parameter specification UTL_FILE_DIR = *
should be used with caution. It turns off directory access checking and makes all directories accessible to the UTL_FILE
functions.
On UNIX systems, the owner of a file created by the FOPEN
function is the owner of the shadow process running the instance. Normally, this owner is ORACLE
. Files created using FOPEN
are always writable and readable using the UTL_FILE
subprograms, but nonprivileged users who need to read these files outside of PL/SQL may need access from a system administrator.
If the parameter initialization file contains only:
UTL_FILE_DIR=/appl/gl/log UTL_FILE_DIR=/appl/gl/out
Then the following file locations and filenames are valid:
FILE LOCATION FILENAME /appl/gl/log L10324.log /appl/gl/out O10324.out
But the following file locations and filename are invalid:
FILE LOCATION FILENAME /appl/gl/log/backup L10324.log # subdirectory /APPL/gl/log L10324.log # uppercase /appl/gl/log backup/L10324.log # dir in name /usr/tmp T10324.tmp # not in INIT.ORA
TYPE file_type IS RECORD (id BINARY_INTEGER, datatype BINARY_INTEGER);
The contents of FILE_TYPE
are private to the UTL_FILE
package. You should not reference or change components of this record.
Procedures in UTL_FILE
can also raise predefined PL/SQL exceptions such as NO_DATA_FOUND
or VALUE_ERROR
.
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|