UTL_File related exception : UTL_FILE « System Packages « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE OR REPLACE PROCEDURE sp_utlfile
  2  IS
  3    v_filehandle UTL_FILE.FILE_TYPE;
  4    v_newline VARCHAR2(1023);
  5  BEGIN
  6    IF NOT UTL_FILE.IS_OPEN(v_filehandle) THEN
  7      v_filehandle := UTL_FILE.FOPEN('c:\temp', 'input_file.txt', 'r');
  8    END IF;
  9
 10    LOOP
 11      BEGIN
 12
 13        UTL_FILE.GET_LINE(v_filehandle, v_newline);
 14        DBMS_OUTPUT.PUT_LINE (v_newline);
 15      EXCEPTION
 16
 17        WHEN NO_DATA_FOUND THEN
 18          EXIT;
 19      END;
 20    END LOOP;
 21
 22    UTL_FILE.FCLOSE(v_filehandle);
 23
 24  EXCEPTION
 25    WHEN UTL_FILE.INVALID_PATH THEN
 26      UTL_FILE.FCLOSE_ALL;
 27      RAISE_APPLICATION_ERROR(-20051, 'Invalid Path');
 28
 29    WHEN UTL_FILE.INVALID_MODE THEN
 30      UTL_FILE.FCLOSE_ALL;
 31      RAISE_APPLICATION_ERROR(-20052, 'Invalid Mode');
 32
 33    WHEN UTL_FILE.INTERNAL_ERROR THEN
 34      UTL_FILE.FCLOSE_ALL;
 35      RAISE_APPLICATION_ERROR(-20053, 'Internal Error');
 36
 37    WHEN UTL_FILE.INVALID_OPERATION THEN
 38      UTL_FILE.FCLOSE_ALL;
 39      RAISE_APPLICATION_ERROR(-20054, 'Invalid Operation');
 40
 41    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
 42      UTL_FILE.FCLOSE_ALL;
 43      RAISE_APPLICATION_ERROR(-20055, 'Invalid Operation');
 44
 45    WHEN UTL_FILE.WRITE_ERROR THEN
 46      UTL_FILE.FCLOSE_ALL;
 47      RAISE_APPLICATION_ERROR(-20056, 'Invalid Operation');
 48  END;
 49  /

Warning: Procedure created with compilation errors.

SQL>
SQL> execute sp_utlfile ;
BEGIN sp_utlfile ; END;

      *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object JAVA2S.SP_UTLFILE is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored


SQL>








31.38.UTL_FILE
31.38.1.File open and close with UTL_FILE package
31.38.2.File open flags
31.38.3.Save table records to a file
31.38.4.Use UTL_FILE package to create a file
31.38.5.Open a file with mode passed in
31.38.6.utl_file.invalid_&&firstparm
31.38.7.UTL_File related exception
31.38.8.UTL_FILE.IS_OPEN
31.38.9.A PL/SQL block to read an operating system file called BLOB.JPG that contains 1 row of binary data.