Home » RDBMS Server » Server Utilities » UTL_FILE_DIR
UTL_FILE_DIR [message #73346] Wed, 31 March 2004 04:07 Go to next message
Milly
Messages: 72
Registered: March 2004
Member
Hi!

I have a problem: I have to use the utl_file and I need to modify the init.ora to permit the write operation, but...:

ALTER SYSTEM SET UTL_FILE_DIR= scope=spfile
                 *
ERRORE alla riga 1:
ORA-02095: Specified initialization parameter cannot be modified

How can I resolve this problem?

thanks!!

 
Re: UTL_FILE_DIR [message #73347 is a reply to message #73346] Wed, 31 March 2004 06:36 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
are you using a 9i database?
in 9i UTL_FILE is obsolete.
you have to create a directory.

this may help you...

-- notes:  
-- 1.	Stored Procedure to write the log files for the Lawson_etl process
-- 2.	Takees 3 input parameters -> filename, message to be written and Mode (read or write)
--	in which the log file is opened.
--	Output -> written to OS file.
-- 3.	init parameter utl_file_dir = c:report (in 8i) or
        create an oracle directory using create directory (9i) and file permsisions are given -->look docs
-- 4.	The Most common exceptions are handled, will add any more.
-- 5.	Initally the file is to be opened in Write mode ( to write the timestamp) 
--	If you want to append data into the same file open the file in apppend mode.
-- WHO=	rajendran

CREATE OR REPLACE PROCEDURE write_log
(
	fname	IN VARCHAR2 ,
	message IN VARCHAR2 ,
	mo	IN VARCHAR2 
)
IS 
log_file  UTL_FILE.FILE_TYPE;         -- file handle for the log file
BEGIN 
log_file := UTL_FILE.FOPEN('c:report',fname,mo);
UTL_FILE.PUTF(log_file,'%sn',message);
UTL_FILE.FCLOSE(log_file);
EXCEPTION
        WHEN NO_DATA_FOUND THEN
		DBMS_OUTPUT.PUT_LINE('no_data_found');
	WHEN UTL_FILE.INVALID_PATH THEN
		DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
	WHEN UTL_FILE.WRITE_ERROR THEN
                DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
      	WHEN OTHERS THEN
                DBMS_OUTPUT.PUT_LINE('other stuff');
END; 
/
 
-------------------------------------------------------------------------------------------------------------------------
-- USAGE
-------------------------------------------------------------------------------------------------------------------------
SQL> ed
Wrote file afiedt.buf

  1  begin
  2  write_log('sampelfile.txt','hello world!','W');
  3  write_log('sampelfile.txt','hello world again!','A');
  4* end;
SQL> /

PL/SQL procedure successfully completed.

SQL> get c:reportsampelfile.txt
  1  hello world!
  2* hello world again!
SQL> 

[Updated on: Sun, 18 December 2005 08:48]

Report message to a moderator

Re: UTL_FILE_DIR [message #73349 is a reply to message #73347] Wed, 31 March 2004 21:03 Go to previous messageGo to next message
Milly
Messages: 72
Registered: March 2004
Member
thank....but I'm using 8i....in this case?
Re: UTL_FILE_DIR [message #73350 is a reply to message #73349] Wed, 31 March 2004 23:09 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
Change the utl_file_dir parameter in your init.ora file, then re-start the database for it to take effect. The utl_file_dir parameter must be a valid existing directory path that exists on your server or * but if you use * for all directories in may create some security issues. You can also set multiple utl_file_dir directories.
Re: UTL_FILE_DIR [message #73351 is a reply to message #73350] Wed, 31 March 2004 23:34 Go to previous messageGo to next message
Milly
Messages: 72
Registered: March 2004
Member
I've tried to do it...but oracle raises the error I've showed....
now I'm trying in oracle 9, creating a directory....adn so....but I've the same problem qith the invalid path....acc...acc..
Re: UTL_FILE_DIR [message #73352 is a reply to message #73351] Thu, 01 April 2004 00:13 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
In 8i, you cannot change the parameter using alter system; You have to edit the init.ora file, then re-start the database. In 9i, the directory must already exist in the operating system, then you must create an Oracle directory object that points to that operating system directory, then reference that directory object in upper case in your pl/sql code. In both 8i and 9i, the directory must be on the server. Can you post a cut and paste of what you tried in 9i, including the error message?
Re: UTL_FILE_DIR [message #73353 is a reply to message #73352] Thu, 01 April 2004 00:19 Go to previous messageGo to next message
Milly
Messages: 72
Registered: March 2004
Member
I have to export data table in a flat file, in a directory not necessarly on the server.
I can't edit the init.ora file....the goal is to do this on a client....

with the utl_file I can't do it (because this works on the server)
with spool I copy the entire statement and not only the data....

any idea?
Re: UTL_FILE_DIR [message #73354 is a reply to message #73353] Thu, 01 April 2004 00:31 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
If you use set echo off from your SQL*Plus script, prior to spooling, it will prevent your sql statement from being displayed. You may also want to set feedback off and heading off and pages 0 and termout off and verify off. You may also want to save your settings, then restore them to their original values, after your spooling. For example:

-- test.sql:
STORE SET saved_settings REPLACE
SET ECHO OFF FEEDBACK OFF HEADING OFF PAGES 0 TERMOUT OFF VERIFY OFF
SPOOL file_name.txt
SELECT * FROM DUAL;
SPOOL OFF
START saved_settings
Re: UTL_FILE_DIR [message #73355 is a reply to message #73354] Thu, 01 April 2004 01:23 Go to previous messageGo to next message
Milly
Messages: 72
Registered: March 2004
Member
ok, but in my .txt file find yet the sql statement....

any idea?
Re: UTL_FILE_DIR [message #73356 is a reply to message #73355] Thu, 01 April 2004 01:34 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
If you include set echo off and set termout off in a .sql file, then start that .sql file, it should not include the sql statement in the .txt file. Notice that you must put the set commands and select statement in a .sql file and start it. It does not work if you just issue the commands from SQL*Plus SQL prompt. How are you running it? If you copy and paste the example that I gave into a file, then start that file, you should end up with a file_name.txt that contains nothing but an x.
Re: UTL_FILE_DIR [message #73358 is a reply to message #73356] Thu, 01 April 2004 05:08 Go to previous messageGo to next message
Milly
Messages: 72
Registered: March 2004
Member
IT WORKS!!!
thank you!!!!!!!!!
Re: UTL_FILE_DIR [message #73426 is a reply to message #73356] Sun, 25 April 2004 06:28 Go to previous messageGo to next message
Stephen P
Messages: 1
Registered: April 2004
Junior Member
Hi,

I want the list of filenames from a given folder and the sub folders. Can you suggests.

Regards,
Stephen P
Re: UTL_FILE_DIR [message #73427 is a reply to message #73426] Sun, 25 April 2004 09:21 Go to previous message
Barbara Boehmer
Messages: 9097
Registered: November 2002
Location: California, USA
Senior Member
Please click on the link below for Tom Kyte's response to that same question.

Previous Topic: If system down
Next Topic: Problem using OEM Import Wizard
Goto Forum:
  


Current Time: Tue Jul 02 08:15:16 CDT 2024