| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.misc -> Re: File I/O from Oracle 7.3 PL SQL
In article <3427F5AB.BFAE29B2_at_commserv.ucsb.edu>, Richard Allard <rallard_at_commserv.ucsb.edu> wrote:
>I am relatively new to PL SQL, so please forgive a very basic question.
>
>I am trying to write a file from an Oracle 7.3 PL SQL script on the
>server. I see in the documentation that the "UTL_FILE" package looks
>like it will do this, but the documentation does not give any examples.
>The documentation shows the function definition, but not the call (or
>maybe the definition and the call are one in the same?).
>
>Can someone post a simple code snigglet with a simple select and the
>file I/O statements?
>
>TIA
>
PROCEDURE read_file ( file_name VARCHAR2) IS
/* Handle to file */
file_handle UTL_FILE.FILE_TYPE;
/* to hold lines from the file */
line VARCHAR2(250);
BEGIN
/* Open file in 'read' mode. Note that the directory must
|| be listed in the init.ora file using
|| the 'utl_file_dir' parameter.
*/
file_handle :=
UTL_FILE.FOPEN('/mydirectory1/filelocation', file_name, 'R');
LOOP
/* Get the next line */
UTL_FILE.GET_LINE(file_handle, line);
/* Do something */
something(line);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
UTL_FILE.FCLOSE (file_handle);
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20000,
'UTL_FILE:Invalid Path');
END read_file;
![]() |
![]() |