Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UTL_FILE => Invalid File Operation

orclrunnerDec 17 2007 — edited Dec 18 2007
I getting the following error:
SQL> @c:\test_utlfile_read
BEFORE OPEN CALL e2b_inform_2004012_81090031_10_200511221100.XML
AFTER OPEN CALL e2b_inform_2004012_81090031_10_200511221100.XML
BEFORE OPEN CALL e2b_inform_2004012_79980006_1_200508250700.XML
DECLARE
*
ERROR at line 1:
ORA-20012: ERROR: ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 449
ORA-29283: invalid file operation
ORA-06512: at line 104

The directory I am reading from is listed in the UTL_FILE_DIR parameter.
The user I am logged in as has read/write privileges on the directory.
On UNIX the WORLD is set to read/execute for the directory.

It seems to be reading the first file in the cursor, but errors when trying to read the second file in the cursor - which makes no sense.

Here is my code:
DECLARE
l_xml_path         varchar2(500) ;(100) := '/var/opt/clin/argus/ast401/xml/archive' ;
l_receive_filename varchar2(255)  ;
l_fileh   utl_file.file_type ;
l_line varchar2(32767) ;
l_text clob ;
l_length number(7) ;
l_start  number(7) ;
l_end    number(7) ;

CURSOR cur IS
     SELECT
              m.receive_filename AS path
     FROM
              esm_user.messages m ;

BEGIN

   OPEN cur ;
      LOOP
        FETCH cur INTO l_receive_filename ;
        EXIT WHEN cur%NOTFOUND ;
        
        -- extract filename 
        l_length             :=   LENGTH(l_receive_filename) ;
        l_start              :=   INSTR(l_receive_filename,'/',-1,1) + 1;
        l_receive_filename   :=   SUBSTR(l_receive_filename,l_start,(l_length - l_start) + 1) ;
                 
        dbms_output.put_line('BEFORE OPEN CALL ' || l_receive_filename) ;

        l_fileh := utl_file.fopen(   l_xml_path
                                   , l_receive_filename
                                   , 'r'
                                   , 32767
                                 ) ; 
                            
        dbms_output.put_line('AFTER OPEN CALL ' || l_receive_filename) ;
   
       LOOP
          BEGIN                       

          utl_file.get_line(  l_fileh
                                 ,l_line
                                ,32767
                               ) ; 

          l_text := l_text || l_line ;

        EXCEPTION
              -- EOF exit loop
              WHEN NO_DATA_FOUND THEN
                  exit ;
              WHEN UTL_FILE.ACCESS_DENIED THEN
                  raise_application_error(-20001,'ACCESS DENIED: Access to the file has been denied by the operating system') ;
              WHEN UTL_FILE.FILE_OPEN THEN
                  raise_application_error(-20002,'FILE OPEN: File is already open') ;
              WHEN UTL_FILE.INTERNAL_ERROR THEN
                  raise_application_error(-20003,'INTERNAL ERROR: Unhandled internal error in the UTL_FILE package') ;
              WHEN UTL_FILE.INVALID_FILEHANDLE THEN
                  raise_application_error(-20004,'INVALID FILE HANDLE: File handle does not exist') ;
              WHEN UTL_FILE.INVALID_FILENAME THEN
                  raise_application_error(-20005,'INVALID FILENAME: A file with the specified name does not exist in the path') ;
              WHEN UTL_FILE.INVALID_MAXLINESIZE THEN
                  raise_application_error(-20006,'INVALID MAXLINESIZE: The MAX_LINESIZE value for FOPEN() is invalid; it should be within the range 1 to 32767') ;
              WHEN VALUE_ERROR THEN
                  raise_application_error(-20006,'VAULE ERROR: GET_LINE value is larger than the buffer') ;
              WHEN UTL_FILE.INVALID_MODE THEN
                  raise_application_error(-20007,'INVALID MODE: The open_mode parameter in FOPEN is invalid') ;
              WHEN UTL_FILE.INVALID_OPERATION THEN
                  raise_application_error(-20008,'INVALID OPERATION: File could not be opened or operated on as requested') ;
              WHEN UTL_FILE.INVALID_PATH THEN
                  raise_application_error(-20009,'INVALID PATH: Specified path does not exist or is not visible to Oracle') ;
              WHEN UTL_FILE.READ_ERROR THEN
                  raise_application_error(-20010,'READ ERROR: Unable to read file') ;
              WHEN OTHERS THEN
               raise_application_error(-20011,sqlcode || ', ' || sqlerrm) ;

           END ;
        END LOOP ;
        
      END LOOP ;
        CLOSE cur ;
    
           -- close the file handle
           IF       utl_file.is_open(l_fileh) 
           THEN
                    utl_file.fclose(l_fileh) ;
           END IF ;
           
     EXCEPTION
        WHEN OTHERS THEN
           IF       utl_file.is_open(l_fileh) 
           THEN
                    utl_file.fclose(l_fileh) ;
           END IF ;
           
           IF     cur%ISOPEN 
           THEN
                  CLOSE cur ;
           END IF ;
           raise_application_error(-20012,'ERROR: ' || sqlerrm) ;
END ;
/
Message was edited by:
jimmyb
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2008
Added on Dec 17 2007
6 comments
7,098 views