Home » SQL & PL/SQL » SQL & PL/SQL » Using utl_file (11.0.2.10)
Using utl_file [message #649350] Wed, 23 March 2016 04:46 Go to next message
OraFerro
Messages: 433
Registered: July 2011
Senior Member
Hi All,

This is my first time using utl_file. I compiled the below testing SP to generate a file in a directory that I have created previously on the server. Still when I run the SP I get"
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at "AFESD3.TEST_P_WRITE", line 6
ORA-06512: at line 2

Note: I suspect that there is something I have to do from the OS, as I am already the creator of the alias, but I can not find documentation about that. Kindly provide your support

create or replace directory FILE_GEN_DIR as 'c:\FILE_GEN_DIR';

GRANT all ON DIRECTORY FILE_GEN_DIR TO  PUBLIC;


CREATE OR REPLACE PROCEDURE  test_p_write
IS
    f  utl_file.file_type;
BEGIN
    
    f := utl_file.fopen ('FILE_GEN_DIR', 'FILE_GEN_DIR.txt', 'W');

    FOR  r  IN  (  SELECT  *
                   FROM   employee
                )
    LOOP
        utl_file.put_line ( f, r.number0) ;
    END LOOP;

    utl_file.fclose (f);
END  test_p_write;


Many thanks,
Ferro
Re: Using utl_file [message #649351 is a reply to message #649350] Wed, 23 March 2016 04:54 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
There is nothing wrong with that code. Have you checked the permissions on the Windows directory? Can you local system user (assuming that the instance is running under that account) read and write to it?
Re: Using utl_file [message #649383 is a reply to message #649351] Wed, 23 March 2016 15:09 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
Find out where the directory object FILE_GEN_DIR is pointing to and then make sure that the Windows user account that is running the Oracle database server has permission to read and write from that directory. Remember that the directory HAS to be on the machine running the Oracle Database.

[Updated on: Wed, 23 March 2016 15:10]

Report message to a moderator

Re: Using utl_file [message #649388 is a reply to message #649383] Wed, 23 March 2016 23:26 Go to previous messageGo to next message
OraFerro
Messages: 433
Registered: July 2011
Senior Member
Thanks a lot John Watson and Bill B, it was an access issue (server OS side not Oracle).

Dear Bill B,
Quote:

Remember that the directory HAS to be on the machine running the Oracle Database.


Actually my second question was going to be how to map a folder that is not on the running machine in Unix and Windows.
I need the output file to be stored on another server, is this NOT possible?

Many thanks,
Ferro
Re: Using utl_file [message #649393 is a reply to message #649388] Thu, 24 March 2016 02:10 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
You can try, but you will have permissions issues. Your database instance isn't running as you, it is running as whatever user is specified for the service and there is no reason to assume that it will have any permissions on a remote device.
Re: Using utl_file [message #649406 is a reply to message #649393] Thu, 24 March 2016 07:20 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
It is fairly easy if you have a windows server running the oracle server and a windows work station. What is the Operating System running your oracle database and the workstation that you want to write the file to. Please supply the version and O/S for both
Re: Using utl_file [message #649434 is a reply to message #649388] Fri, 25 March 2016 07:02 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
OraFerro wrote on Thu, 24 March 2016 00:26

Actually my second question was going to be how to map a folder that is not on the running machine in Unix and Windows.
I need the output file to be stored on another server, is this NOT possible?


Mount/Map NAS drive on both database server and all other servers where you want files to be accessed from. I use it all the time, especially when dealing with RAC. Imagine you run data pump export and then need to import it back. Without same NAS mounted on all RAC nodes you would be forced to login to same node export dump resides on. Same way, for example, mounting NAS on both database & application server allows application to create/receive file, put it on NAS and then use it as external table source from...

SY.
Previous Topic: connection issue-how to reset ?
Next Topic: Table LOCK
Goto Forum:
  


Current Time: Fri Apr 19 01:51:48 CDT 2024