Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Help! - File I/O thru PL/SQL

Re: Help! - File I/O thru PL/SQL

From: Ricardo Rocha <rrocha_at_usagate.net>
Date: 1997/03/15
Message-ID: <01bc3122$c486a9e0$6564c7d0@rrocha>#1/1

The following anonymous PL/SQL block shows the basic usage of the UTL_FILE package:

DECLARE

	Read_mode		CONSTANT VARCHAR2(1) := 'r';
	Write_mode		CONSTANT VARCHAR2(1) := 'w';
BEGIN

-- Create or replace text file in current directory
my_file := utl_file.fopen(Current_directory, File_name, Write_mode);
-- Write some lines...
utl_file.put_line(my_file, '1. This is the first line'); utl_file.put_line(my_file, '2. This is the second line'); utl_file.put_line(my_file, '3. This is the third line');
-- Formatted … a la C language
utl_file.putf(my_file, 'Today is the %s!!!\n', TO_CHAR(SYSDATE));
-- Done, close the file
utl_file.fclose(my_file);
-- Reopen the file to read previously written lines
my_file := utl_file.fopen(Current_directory, File_name, Read_mode); BEGIN -- Get the next line in the file utl_file.get_line(my_file, my_line); -- Show the world what we got dbms_output.put_line(my_line); EXCEPTION WHEN NO_DATA_FOUND THEN -- Exahusted utl_file.fclose(my_file); END; EXCEPTION WHEN utl_file.invalid_path THEN dbms_output.put_line('Invalid path'); WHEN utl_file.invalid_mode THEN dbms_output.put_line('Invalid mode'); WHEN utl_file.invalid_filehandle THEN dbms_output.put_line('Invalid file handle'); WHEN utl_file.invalid_operation THEN dbms_output.put_line('Invalid operation'); WHEN utl_file.read_error THEN dbms_output.put_line('Read error'); WHEN utl_file.write_error THEN dbms_output.put_line('Write error'); WHEN utl_file.internal_error THEN dbms_output.put_line('Internal error');
END;
.
/ Received on Sat Mar 15 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US