Open a file with mode passed in : UTL_FILE « System Packages « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE OR REPLACE FUNCTION fopen
  2     (loc_in IN VARCHAR2,
  3      file_in IN VARCHAR2,
  4      mode_in IN VARCHAR2 := 'R')
  5      RETURN UTL_FILE.FILE_TYPE
  6  IS
  7     fID UTL_FILE.FILE_TYPE;
  8  BEGIN
  9     fID := UTL_FILE.FOPEN (loc_in, file_in, mode_in);
 10     RETURN fid;
 11  EXCEPTION
 12     WHEN UTL_FILE.INVALID_OPERATION
 13     THEN
 14        IF mode_in = 'A'
 15        THEN
 16           fID := UTL_FILE.FOPEN (loc_in, file_in, 'W');
 17           RETURN fid;
 18        ELSE
 19           RAISE;
 20        END IF;
 21  END;
 22  /


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.