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: File I/O from Oracle 7.3 PL SQL

Re: File I/O from Oracle 7.3 PL SQL

From: Ben Harmon <benh_at_dascom.nospam.com>
Date: 1997/09/23
Message-ID: <609gcs$10e@news9.noc.netcom.net>#1/1

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;



Ben Harmon
benh_at_dascom.nospam.com
**Please remove .nospam if you want to mail me**
Received on Tue Sep 23 1997 - 00:00:00 CDT

Original text of this message

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