1]
In this Document
Symptoms
Cause
Solution
References
Applies to:
PL/SQL - Version: 9.2.0.1 to 11.2.0.1 - Release: 9.2 to 11.2
Information in this document applies to any platform.
***Checked for relevance on 04-Jan-2010***
Symptoms
Executing a PL/SQL stored procedure to open a file on the file system where the Oracle Server is
running using UTL_FILE.FOPEN () method is throwing the following exception
The directory to receive the file has already been created via the DDL statement CREATE
DIRECTORY and permissions have been granted to the oracle user who is executing the
PL/SQL procedure via the GRANT READ and GRANT WRITE statements.
The UTL_FILE.FOPEN statement quotes the actual directory path in the call
e.g. fh := UTL_FILE.FOPEN('/home/demo/schema/data', 'myfile.html','w',32767);
Cause
From 9i R2 onwards, the first argument passed to UTL_FILE.FOPEN can either be the full path
name or the value of the DIRECTORY_NAME column of the ALL_DIRECTORIES table.
However, using the full path name still requires that this be entered into the UTL_FILE_DIR
parameter in the init.ora. Since the introduction of the facility to enter the DIRECTORY name,
this feature is effectively deprecated and it is recommended that you quote the DIRECTORY
name.
Solution
Example:
Assume you want to open a file called myfile.html for writing in the directory
/home/demo/schema/data
The FOPEN () is then invoked with the following arguments as shown in the PL/SQL code
snippet below:
declare
TYPE file_type IS RECORD (
id BINARY_INTEGER,
datatype BINARY_INTEGER);
fh UTL_FILE.FILE_TYPE;
begin
fh := UTL_FILE.FOPEN('DATA_FILE_DIR', 'myfile.html','w',32767);
UTL_FILE.FCLOSE(fh);
end;
/
Please notice that the directory passed to UTL_FILE.OPEN () method is the directory name
DATA_FILE_DIR and not the directory PATH given by /home/demo/schema/data.
The OPEN method will query the ALL_DIRECTORIES table using the directory name to pull
the DIRECTORY_PATH.
References
NOTE:44307.1 - Top Articles Using UTL_FILE Package to Perform File I/O (UNIX)
Oracle 9i Supplied PL/SQL Packages and Types Reference, Release 2 (9.2), Part Number
A96612-01