UTL_FILE

DECLARE 
  myvariable     VARCHAR2(32767); 
  myfilepointer  UTL_FILE.FILE_TYPE; 

BEGIN 
  myfilepointer := UTL_FILE.FOPEN('myDIRECTORY','myfilename','open_mode',max_linesize);

  UTL_FILE.GET_LINE(myfilepointer,myvariable,line_length);

  UTL_FILE.FCLOSE(myfilepointer); 

  UTL_FILE.FCOPY('srcDIRECTORY','srcfilename','destDIRECTORY','destfilename',start,end);
  UTL_FILE.RENAME('srcDIRECTORY','srcfilename','destDIRECTORY','destfilename',overwrite);
  UTL_FILE.FREMOVE('myDIRECTORY','myfilename');

EXCEPTION
  WHEN UTL_FILE.NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: No Data Found')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.INVALID_PATH THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Invalid Path')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.INVALID_MODE THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Invalid Mode')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.INVALID_FILEHANDLE THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Invalid Filehandle')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.INVALID_FILENAME THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Invalid Filename')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.INVALID_OPERATION THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Invalid Operation')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.INVALID_OFFSET THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Invalid Offset')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.READ_ERROR THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Read Error')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.WRITE_ERROR THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Write Error')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.INTERNAL_ERROR THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Internal Error')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.ACCESS_DENIED THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Access Denied')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.RENAME_FAILED THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Rename Failed')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.DELETE_FAILED THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: Delete Failed')
    UTL_FILE.FCLOSE_ALL;
  WHEN UTL_FILE.NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('UTL_FILE: No Data Found')
    UTL_FILE.FCLOSE_ALL;
  WHEN OTHERS THEN RAISE;
END; 

DIRECTORY

The Directory object must be created before you can write files to it

open_mode

r -- read textw -- write texta -- append textrb -- read byte modewb -- write byte modeab -- append byte mode

max_linesize

Maximum number of characters for each line, including the newline character, for this file (minimum value 1, maximum value 32767). If unspecified, Oracle supplies a default value of 1024

line_length

The number of bytes read from the file. Default is NULL. If NULL, Oracle supplies the value of max_linesize. Maximum value is 32767.

start

Line number at which to begin copying. The default is 1 for the first line

end

Line number at which to stop copying. The default is NULL, signifying end of file

overwrite

Default is FALSE. Specifies whether or not to overwrite an existing file.