Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

utl_file.fopen does not work in procedure

user3203905Jun 24 2023 — edited Jun 24 2023

Hi,

we are migrating from an Oracle 12 DB to the 19c version. I have some procedures that write data to files on the DB server via utl_file.fopen. I have created the directory to write to before via CREATE DIRECTORY.
Here is the example code

DECLARE 
f_output                  utl_file.file_type;
BEGIN
 f_output := UTL_FILE.fopen('TMP', 'test.csv', 'W');
 UTL_FILE.put_line(f_output,'TestLine');
 UTL_FILE.fflush(file => f_output);
 UTL_FILE.FCLOSE(f_output);
END;

Runing this code works fine, file is created, content written, file closed.

BUT if i create a procedure with exact the same code and run this procedure, with the same user on the same server in the same session as the code above…

CREATE OR REPLACE PROCEDURE test_out IS
f_output                  utl_file.file_type;
BEGIN
 f_output := UTL_FILE.fopen('TMP', 'test.csv', 'W');
 UTL_FILE.put_line(f_output,'TestLine');
 UTL_FILE.fflush(file => f_output);
 UTL_FILE.FCLOSE(f_output);
END;
/
exec test_out;

then this does NOT work but throws this ORA error

ORA-29280: invalid directory object
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at "PFK.TEST_OUT", line 5
ORA-06512: at line 2

Does anyone have an idea why the code does not work within a procedure? All other parameters are the same, DB / Server / User / Permissions

Greetings, sun

This post has been answered by Solomon Yakobson on Jun 24 2023
Jump to Answer
Comments
Post Details
Added on Jun 24 2023
5 comments
2,807 views