Solved

How to write to a file ?

Posted on 2004-04-19
8
2,715 Views
Last Modified: 2007-12-19
Hello,

I have a stupid problem...
I know that I have to use the UTL_FILE built in and I know how to use it.
I know that I have to give access to the folder I want to use with specifying UTL_FILE_DIR in the init.ora file.
My problem is that I do not have any init.ora file anywhere....
I have tried to create a simple one with the new UTL_FILE_DIR sentence but it doesn't seem to work.

To be more precise, my DB is installed on Computer1 and I run my queries from Computer2 from TOAD.
And I want to have some output in a file.
Where do I have to set my Init.ora file ? On Computer1 or Computer2 ? and in which folder ? (I have told... stupid question...)
My generated file can be on Computer1 ?
Can you give me the example of Init.ora file ? I can set only the UTL_FILE_DIR in it ?

btw, I have also read that I could give access with ALTER SYSTEM command while logged as SYSDBA. But it doesn't seem to work, giving me the error 'Cannot change initialization options' or something like that...
0
Comment
Question by:Jarodtweiss
8 Comments
 
LVL 23

Assisted Solution

by:seazodiac
seazodiac earned 50 total points
Comment Utility
thato's because your database is started with SPFILE instead of PFILE.

try this in Toad or SQLPLUS

SQL> select count(*) from v$spparameter where isspecified ='TRUE';



if you get count(*) >0, then you are using SPFILE,


And if you are lucky (running database version 8i or later),

then you can use this to modify utl_file_dir dynamically

SQL> alter system set ult_file_dir='/foo/bar/dir1' scope=spfile
0
 
LVL 10

Expert Comment

by:SDutta
Comment Utility
If you are running a 9i (9.2) database you don't need to set a UTL_FILE_DIR in the init.ora or pfile anymore.

Log in as SYSDBA
SQL> CREATE DIRECTORY my_directory AS 'C:\NEW'; -- this is on the DB server
SQL> GRANT READ ON DIRECTORY my_directory TO scott; -- read is enough to read/write to the location

Now you can connect as SCOTT and use 'my_directory' as the first parameter in UTL_FILE.FOPEN like this
file_handle := utl_file.fopen('my_directory','output.txt','w');

Note : Case of the directory is important here, use it in the same case that it was created.

If you need to write to a remote location (not on the DB server) then the database and listener services need to run under a domain usercode which has access to the remote location.
0
 
LVL 2

Expert Comment

by:GDE
Comment Utility
if you use NT platform, open regedit, read HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME[0, 1, 2 or other ]\ORA_TEST_PFILE, may be your init.ora have another place and file name.
if you don`t find him, run
select NAME, VALUE
    from v$parameter
    where isdefault = 'FALSE'
it`s be your init.ora (NAME=VALUE), put them on normal place.
create file dir, make access to him,
then change parameter UTL_FILE_DIR in new init.ora
Now you can use UTL_FILE

Best regards
Dmitry.
0
 
LVL 4

Author Comment

by:Jarodtweiss
Comment Utility
@seazodiac

"select count(*) from v$spparameter where isspecified ='TRUE'" gives me 29
So I run the alter which is accepted.
Then I run teh select again and it gives me 30. If I check in the v$parameter, the utl_file_dir has not been changed
andI still have the same problem then

@SDutta

I'm using Oracle 9.2 but your solution doesn't seem to work
I connect as a SYSDBA (either on my machine or directly on the DB server)
the CREATE DIRECTORY and GRANT were ok (no error) but when I run the utl_file commands, I still have the error (not a vlalid...)
I checked and cheked again the path and case and it was ok.

@GDE

I'm using W2K
and I have nothing in the registry ang the select show me the path of dumps and control files. That's all

Any other idea ? or precision if your solution should have work. I may have done something wrong...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Expert Comment

by:GDE
Comment Utility
Exporting the Server Parameter File
You can export a server parameter file to create a traditional text initialization parameter file. Reasons for doing this include:

Creating backups of the server parameter file

For diagnostic purposes, listing all of the parameter values currently used by an instance. This is analogous to the SQL*Plus SHOW PARAMETERS command or selecting from the V$PARAMETER or V$PARAMETER2 views.

Modifying of the server parameter file by first exporting it, editing the output file, and then recreating it.

The exported file can also be used to start up an instance using the PFILE option.

The CREATE PFILE statement is used to export a server parameter file. You must have the SYSDBA or the SYSOPER system privilege to execute this statement. The exported file is created on the database server machine. It contains any comments associated with the parameter in the same line as the parameter setting.

The following example creates a text initialization parameter file from the server parameter file:

CREATE PFILE FROM SPFILE;


Because no names were specified for the files, a platform-specific name is used for the initialization parameter file, and it is created from the platform-specific default server parameter file.

The following example creates a text initialization parameter file from a server parameter file where the names of the files are specified:

CREATE PFILE='/u01/oracle/dbs/test_init.ora'
       FROM SPFILE='/u01/oracle/dbs/test_spfile.ora';

http://download-west.oracle.com/docs/cd/A91202_01/901_doc/server.901/a90117/create.htm#1012672

Best regards
Dmitry.
0
 
LVL 4

Author Comment

by:Jarodtweiss
Comment Utility
Finally it's ok.
I was able to create manually a init.ora file and it is loaded correctly in Oracle.
I can now write to the file.
I'm checking if I don't have extra problems before closing the question.
0
 
LVL 2

Accepted Solution

by:
GDE earned 75 total points
Comment Utility
if you don`t find init.ora file create him from v$parameter view, then run create blah-blah-blah...FROM... Stop db, restart using parameter pfile. Of course, change UTL_FILE_DIR parameter.

Best regards
Dmitry.
0
 
LVL 4

Author Comment

by:Jarodtweiss
Comment Utility
Now I have an error when I write to the file.
In all the case, it is ok except for that line :

         UTL_FILE.PUT_LINE(file_id, myQuery);
Notice that myQuery is a VARCHAR2 and that has a length of 20 000 or so...
And I receive a UTL_FILE.WRITE_ERROR exception.
Is it because of the length ? Do I have to substring it ? There is no other way ?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to recover a database from a user managed backup

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now