Oracle9i Supplied PL/SQL Packages and Types Reference Release 2 (9.2) Part Number A96612-01 |
|
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:
UTL_FILE
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 you can access.
In the past, accessible directories for the UTL_FILE
functions were specified in the initialization file using the UTL_FILE_DIR
parameter. However, UTL_FILE_DIR
access is not recommended. It is recommended that you use the CREATE DIRECTORY
feature, which replaces UTL_FILE_DIR
. Directory objects offer more flexibility and granular control to the UTL_FILE
application administrator, can be maintained dynamically (that is, without shutting down the database), and are consistent with other Oracle tools. CREATE DIRECTORY
privilege is granted only to SYS
and SYSTEM
by default.
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.
Given the following:
SQL> CREATE DIRECTORY log_dir AS '/appl/gl/log'; SQL> GRANT READ ON DIRECTORY log_dir TO DBA; SQL> CREATE DIRECTORY out_dir AS '/appl/gl/user''; SQL> GRANT READ ON DIRECTORY user_dir TO PUBLIC;
The following file locations and filenames are valid and accessible as follows:
File Location | Filename | Accessible By |
---|---|---|
|
|
Users with DBA privilege |
|
|
All users |
The following file locations and filenames are invalid:
Caution: There are no user-level file permissions. |
Procedures in UTL_FILE
can also raise predefined PL/SQL exceptions such as NO_DATA_FOUND
or VALUE_ERROR
.
The contents of FILE_TYPE
are private to the UTL_FILE
package. You should not reference or change components of this record.
TYPE file_type IS RECORD ( id BINARY_INTEGER, datatype BINARY_INTEGER);
|
Copyright © 2000, 2002 Oracle Corporation. All Rights Reserved. |
|