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: problems with UTL_FILE

Re: problems with UTL_FILE

From: damorgan <damorgan_at_exesolutions.com>
Date: Wed, 27 Nov 2002 16:39:44 GMT
Message-ID: <3DE4F54E.C991CF51@exesolutions.com>


Mark wrote:

> Hello,
>
> I'm having problems with UTL_FILE.
>
> Below is a procedure which I'm writing. At the moment, all I'm
> trying to do is to open one file, read the contents of it and
> write it to another.
>
> It's not working in 2 ways.
>
> It's raising a "User-Defined Exception" at the line
>
> UTL_FILE.FCLOSE(vf_write_file);
>
> If I comment out this line, the exception isn't thrown. What's
> confusing me is that I'm not raising *any* user defined
> exceptions within the code.
>
> If I comment out the "UTL_FILE.FCLOSE(vf_write_file);" line,
> no exceptions are raised, but the destination file
> (teamReport.html) is empty, even though the sourse file
> has stuff in it.
>
> I'm really confused about this.
>
> ----------------------------------------------------------------
>
> PROCEDURE create_team_report
> AS
>
> vf_read_file UTL_FILE.FILE_TYPE;
> vf_write_file UTL_FILE.FILE_TYPE;
> vv_retrieved_line VARCHAR2(240);
> vv_file_path VARCHAR2(4000);
>
> BEGIN
>
> vf_write_file := UTL_FILE.FOPEN('/usr/apps/oracle/writefiles/devt'
> ,'teamReport.html'
> ,'W'
> );
>
> vf_read_file := UTL_FILE.FOPEN('/usr/apps/oracle/writefiles/devt'
> ,'htmlHeader.html'
> ,'R'
> );
>
> LOOP
> BEGIN
> UTL_FILE.GET_LINE(vf_read_file, vv_retrieved_line);
>
> UTL_FILE.PUTF(vf_write_file, vv_retrieved_line);
>
> EXCEPTION
> WHEN OTHERS THEN
> EXIT;
> END;
> END LOOP;
>
> UTL_FILE.FCLOSE(vf_read_file);
>
> UTL_FILE.FCLOSE(vf_write_file);
>
> 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_OPERATION THEN
> DBMS_OUTPUT.PUT_LINE('Invalid operation');
> WHEN OTHERS THEN
> DBMS_OUTPUT.PUT_LINE(SQLERRM);
>
> END create_team_report;
>
> Thanks muchly for any assistance.
>
> Mark

All exceptions generated by UTL_FILE are, by definition, user defined exceptions. Try this exception block at the end of your procedure.

                              EXCEPTION
                                 WHEN NO_DATA_FOUND THEN
                                    .. do something
                                 WHEN utl_file.invalid_mode THEN
                                    .. do something
                                WHEN utl_file.invalid_path THEN
                                    .. do something
                                WHEN utl_file.invalid_filehandle THEN
                                    .. do something
                                WHEN utl_file.invalid_operation THEN
                                    .. do something
                                WHEN utl_file.read_error THEN
                                    .. do something
                                WHEN utl_file.write_error THEN
                                    .. do something
                                WHEN utl_file.internal_error THEN
                                    .. do something
                                 WHEN OTHERS THEN -- logs end of procdure if
it fails
                                    .. do something
                              END;

Daniel Morgan Received on Wed Nov 27 2002 - 10:39:44 CST

Original text of this message

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