1. Home
  2. Knowledge Base
  3. Database Administration
  4. How to check the UTL_FILE_DIR parameter?

How to check the UTL_FILE_DIR parameter?

CREATE OR REPLACE procedure utl_file_test_write1 (
path in varchar2,
filename in varchar2,
firstline in varchar2,
secondline in varchar2)
is
output_file utl_file.file_type;
begin
output_file := utl_file.fopen (path,filename, ‘W’);

utl_file.put_line (output_file, firstline);
utl_file.put_line (output_file, secondline);
utl_file.fclose(output_file);

–exception
— when others then null;
end;
/

begin
utl_file_test_write1 (
‘/u03/users/ofsa/ofsatest/oracle_utl_data’,
‘utl_file_test’,
‘first line’,
‘second line’
);
end;
/

This works too –

SET SERVEROUTPUT ON
DECLARE
fid UTL_FILE.FILE_TYPE;
v VARCHAR2(32767);
PROCEDURE recNgo (str IN VARCHAR2)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE (‘UTL_FILE error ‘ || str);

UTL_FILE.FCLOSE (fid);
END;
BEGIN
/* Change the directory name to one to which you at least
|| THINK you have read/write access.
*/
fid := UTL_FILE.FOPEN (‘/u03/users/ofsa/ofsatest/oracle_utl_data’, ‘utl_file_test’, ‘R’);
UTL_FILE.GET_LINE (fid, v);
dbms_output.put_line (v);
UTL_FILE.FCLOSE (fid);

fid := UTL_FILE.FOPEN (‘/u03/users/ofsa/ofsatest/oracle_utl_data’, ‘utl_file_test_10’, ‘W’);
UTL_FILE.PUT_LINE (fid, v);
UTL_FILE.FCLOSE (fid);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH
THEN recNgo (‘invalid_path’);
WHEN UTL_FILE.INVALID_MODE
THEN recNgo (‘invalid_mode’);
WHEN UTL_FILE.INVALID_FILEHANDLE
THEN recNgo (‘invalid_filehandle’);
WHEN UTL_FILE.INVALID_OPERATION
THEN recNgo (‘invalid_operation’);
WHEN UTL_FILE.READ_ERROR
THEN recNgo (‘read_error’);
WHEN UTL_FILE.WRITE_ERROR
THEN recNgo (‘write_error’);
WHEN UTL_FILE.INTERNAL_ERROR
THEN recNgo (‘internal_error’);
END;
/

message for success below.

first line

PL/SQL procedure successfully completed.

SQL> exit

The following two tabs change content below.

Arjun Raja

Latest posts by Arjun Raja (see all)

Updated on June 2, 2021

Was this article helpful?

Related Articles

Leave a Comment