Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attempting to write to a file

Status
Not open for further replies.

eyetry

Programmer
Oct 2, 2002
560
US
trying to figure out how to write a procedure that will write output to a file. Ran this in sqlplus but it errors...

declare
f utl_file.file_type;
s varchar2(50) := 'this is a test record';
begin
f := utl_file.fopen('EXAMPLEDATA','c:\example1.txt','W');
utl_file.put_line(f,s);
utl_file.fclose(f);
end;


What am I doing wrong?
 
You're probably making the common error of trying to create a file on your PC's C drive. UTL_FILE doesn't work that way. It writes to a file on the server where the database resides.
 
in the example below is 'EXAMPLEDATA' then the target path on the DB server?

declare
f utl_file.file_type;
s varchar2(50) := 'this is a test record';
begin
f := utl_file.fopen('EXAMPLEDATA','example1.txt','W');
utl_file.put_line(f,s);
utl_file.fclose(f);
end;
 
That's correct. You'll have to be able to log on to the DB server to look at it.
 
resolved used

SELECT GET_UTL_FILE_DIR_FNC INTO L_UTL_FILE_DIR from dual;

declare
f utl_file.file_type;
s varchar2(50) := 'this is a test record';
begin
f := utl_file.fopen(L_UTL_FILE_DIR,'example1.txt','W');
utl_file.put_line(f,s);
utl_file.fclose(f);
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top