Posts Tagged file handling
    Here is a simple code for reading the entire contents of a file into a string in PL/SQL using utl_file package.
It iterates through the file, concatenating each line at a time using get_line function.
declare
  f_in utl_file.file_type;
  s_in varchar2(10000);
  string varchar2(32000);

begin
 f_in := utl_file.fopen('SAMPLEDIR','input.txt','R');

   loop
      begin
        utl_file.get_line(f_in,s_in);
        EXCEPTION
          WHEN NO_DATA_FOUND THEN
        EXIT;

        string:= string || s_in;

      end;
   end loop;
 utl_file.fclose(f_in);
end;

In the above code SAMPLEDIR is a logical entry in the database pointing to a directory which needs to be created before performing any file handling procedures. The following link lets you get started with file handling in PL/SQL in case if you are new to it. http://www.devshed.com/c/a/Oracle/Reading-Text-Files-using-Oracle-PLSQL-and-UTLFILE/1/