UTL FILE It is a PL/SQL package that can be used to read/write to operating system files on a local system, where the database resides. List of UTL FILE subprograms FCLOSE : Closing a file FCLOSE_ALL : Closes all file handlers FCOPY : Copies a part of the file to the newly created file FFLUSH : Writes all pending output to the file FGETATTR : Reads and returns the attributes of a disk file. ex file name,file length,location. FGETPOS : Returns the current relative offset position with in a file to byte as binary integer FOPEN : Opens a file for input or output FOPEN_NCHAR : Unicode for input or output FREMOVE : Deletes a diskfile location and file name FRENAME : Renames existing to a new file name FSEEK : Adjusts the file pointer backward/forward GET_LINE : Reads text, following are the parameters (file, buffer, length) GET_LINE_NCHAR : Reads text in unicode GET_ROW : Reads a row string values IS_OPEN : Determines if a file handle refers to an open file NEW_LINE : Writes one or more operating system specific line terminators to a new file (file, lines) PUT : Writes a string to a file PUT_LINE : Writes a line to a file & also appends an operating system specific terminator, if already written it starts then new line with CR/LF. PUT_LINE_NCHAR : Writes a unicode string to a file PUTF : Formatting PUTF_NCHAR : Writes unicode string to file for formatting PUT_RAW : Accepts input as raw data value & writes the values to a output buffer Sample program ( With Error) create or replace procedure sal_status(p_filedir in varchar2, p_filename in varchar2) is v_filehandle UTL_FILE.FILE_TYPE; cursor emp_info is select last_name,salary,department_id from employees order by department_id; v_newdeptno employees.department_id%type; v_olddeptno employees.department_id%type :=0; begin v_filehandle :=UTL_FILE.FOPEN (p_filedir, p_filename, 'W'); UTL_FILE.PUTF (v_filehandle, 'SALARY REPORT GENERATED ON %s\n', sysdate); UTL_FILE.NEW_LINE (v_filehandle); for v_emp_rec in emp_info loop v_newdeptno:=v_emp_rec.department_id; if v_newdeptno!=v_olddeptno then UTL_FILE.PUTF(v_filehandle, 'DEPARTMENT: %s\n', v_emp_rec.department_id); end if; UTL_FILE.PUTF(v_filehandle, ' EMPLOYEE: %s earns : %s\n', v_emp_rec.last_name,v_emp_rec.salary); v_olddeptno:=v_newdeptno; end loop; UTL_FILE.PUT_LINE(v_filehandle, ' END OF REPORT '); UTL_FILE.FCLOSE(v_filehandle); EXCEPTION when UTL_FILE.INVALID_FILEHANDLE then RAISE_APPLICATION_ERROR (-20008, ' Invalid file'); when UTL_FILE.WRITE.ERROR then RAISE_APPLICATION_ERROR (-20003, ' unable to write'); end sal_status; / EXCEPTIONS IN UTL_FILE Invalid_path ; Invalid filename of file location Invalid_mode : Parameter in fopen is invalid Invalid_filehandle : Invalid file handle Invalid_operation : Could not be opened or operated Read_error : An operating system error occured during read operation Write_error : An operating system error occured during write operation internal_error : An unspecified error in PL/SQL