Set ServerOutput On
declare
v_line varchar2(32767);
c_location constant varchar2(80) := 'UTL_FILE_TEST'
;
c_filename constant varchar2(80) := 'test.txt';
v_handle Utl_File.File_Type;
procedure Put_Line ( p_buffer in varchar2 ) is begin
Utl_File.Put_Line (
file => v_handle,
buffer => p_buffer,
autoflush => true ) ;
end Put_Line;
begin
v_handle := Utl_File.Fopen (
location => c_location,
filename => c_filename,
open_mode => 'w',
max_linesize => 32767 );
Utl_File.Put (
file => v_handle,
buffer => '1st line. Using Put' );
Utl_File.New_Line (
file => v_handle,
lines => 3 );
Utl_File.Putf (
file => v_handle,
format => 'Error in %s due to %s.\nCall %s',
arg1 => 'something',
arg2 => 'something else',
arg3 => 'somebody' );
Utl_File.New_Line (
file => v_handle );
Utl_File.Fflush ( file => v_handle ) ;
Wait.Go ;
for j in 3..10
loop
Put_Line ( To_Char(j) || 'th line. It''s not too long' );
Wait.Go;
end loop;
Utl_File.Fclose ( file => v_handle );
v_handle := Utl_File.Fopen (
location => c_location,
filename => c_filename,
open_mode => 'r',
max_linesize => 32767 );
begin
loop
Utl_File.Get_Line (
file => v_handle,
buffer => v_line );
);
Dbms_Output.Put_Line ( v_line || '--' );
end loop;
exception when no_data_found then null; end;
Utl_File.Fclose ( file => v_handle );
end;
/