Question

Hi, everybody. I am new to PL/SQL and Oracle Databases. I need to read/write file that exists on server so i'm using utl_file.fopen('/home/tmp/','text.txt','R') but Oracle shows error 'invalid directory path'.

Main problem is that i have only user privileges, so i cant use commands like create directory user_dir as '/home/temp/' or view utl_file_dir with just show parameter utl_file_dir; I used this code to view utl_file_dir:

SQL> set serveroutput on;
SQL> Declare
  2      Intval number;
  3      Strval varchar2 (500);
  4      Begin
  5       If (dbms_utility.get_parameter_value('utl_file_dir', intval,strval)=0)
  6      Then dbms_output.put_line('value ='||intval);
  7      Else dbms_output.put_line('value = '||strval);
  8      End if;
  9      End;
 10  /

and output was 'value = 0'.

I google'd much but didnt find any solution of this problem, so i'm asking help here.

To read file i used this code:

    declare
    f utl_file.file_type;
    s varchar2(200);
begin
    f := utl_file.fopen('/home/tmp/','text.txt','R');
    loop
        utl_file.get_line(f,s);
        dbms_output.put_line(s);
    end loop;
exception
    when NO_DATA_FOUND then
        utl_file.fclose(f);
end;
Was it helpful?

Solution

If you do not have permission to create the directory object (and assuming that the directory object does not already exist), you'll need to send a request to your DBA (or someone else that has the appropriate privileges) in order to create a directory for you and to grant you access to that directory.

utl_file_dir is an obsolete parameter that is much less flexible than directory objects and requires a reboot of the database to change-- unless you're using Oracle 8.1.x or you are dealing with a legacy process that was written back in the 8.1.x days and hasn't been updated to use directories, you ought to ignore it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top