Tuesday, July 20, 2010

Simple UTL_FILE Script to create & write in a file

Below PL/SQL block creates a file named 'sample.txt' with 'welcome' word in it under the Oracle Directory Named UTL_DIR [Can be created using CREATE DIRECTORY]

We can use utl_file_dir instead of CREATE DIRECTORY in that case we need to specify the whole path of the UNIX directory instead of the just the Directory name[i.e.., UTL_DIR]

Make sure you have necessary permissions.

Using utl_file_dir is not a recommended one.

Declare
file1 utl_file.file_type;
Begin
file1:= utl_file.fopen('UTL_DIR','sample.txt','w');
utl_file.put_line(file1,'Welcome' );
utl_file.fclose(file1);
end;
/

No comments: