Pages

Friday, February 8, 2013

PLSQL Write to txt file using UTL_File.fopen

In order to write to a text file from PLSQL using UTL_FILE do the following

Find out where your utl directory has been set in the init.ora
SELECT *
  FROM V$PARAMETER
  WHERE NAME = 'utl_file_dir'


Then you can do something like the following:

declare
    f utl_file.file_type;
    s varchar2(200) := 'this is some info';
   
begin
    f := utl_file.fopen('/usr/tmp','sample2.txt','W');
    utl_file.put_line(f,s);
    utl_file.fclose(f);
end;