Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: UTL_FILE code example
Here's a simple example on how to use UTL_FILE package:
declare
file utl_file.file_type;
begin
/* Type "set serveroutput on" to see the lines displayed by dbms_output */
dbms_output.enable; dbms_output.put('>>> Begin'); dbms_output.new_line;
UTL_FILE_DIR in the INIT.ORA file. This parameter can be "*" for all the directories */ if ( utl_file.is_open(file) ) then dbms_output.put_line('>>> File opened'); utl_file.put_line (file, 'something writen in the file'); dbms_output.put_line('>>> Line writen'); utl_file.fflush (file); dbms_output.put_line('>>> Buffer flushed'); utl_file.fclose (file); dbms_output.put_line('>>> File closed'); else dbms_output.put_line('>>> File not open');end if;
dbms_output.put_line('>>> Invalid path'); when utl_file.invalid_filehandle then
dbms_output.put_line('>>> Invalid file handle'); when utl_file.invalid_mode then
dbms_output.put_line('>>> Invalid mode'); when utl_file.invalid_operation then
dbms_output.put_line('>>> Invalid operation'); when utl_file.write_error then
dbms_output.put_line('>>> Write error'); when utl_file.read_error then dbms_output.put_line('>>> Read error'); when utl_file.internal_error then dbms_output.put_line('>>> Internal error'); when others then dbms_output.put_line('>>> Other error');end;
There is no default directory.
The directory must be passed on the utl_file.fopen function
and this directory must be given in an UTL_FILE_DIR parameter
in the init.ora file.
Hope this will help you.
prakbala_at_hotmail.com a écrit dans le message <7qbm5t$44u$1_at_nnrp1.deja.com>...
>Will someone please give me an example of how to write
>a file out using UTL_FILE function ?
>
>For ex:
>
>cursor c1 is
> Select emp_name,emp_dept,emp_salary from employee;
>
>I would like to write this info to a flat file. Also I would
>like to know what changes I need to make in ORAINIT file for
>default UTL_FILE directory of C:\flatfile.
>
>Thank You.
>
>PB
>
>
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.
Received on Mon Aug 30 1999 - 04:20:50 CDT