Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

reading records from from text file

642819Jan 26 2009 — edited Jan 26 2009

hi guys,

i'm working on this project that reads records in a text file located in a server directory and then inserts it into the table using UTL_FILE Utility. my problem is that i can't do the loop to read multiple records in the text file. so far here is what i got.

sample text file data:
----------------------------------
H00001XXXXX888888
D123458888555ENTJOHN DOE             XXXX
D543219999777ENTALEX WALKER        YYYY
D882760000880ENTKRIS BYRON           ZZZZ
T00003WALKEN

=================================================

declare
   l_directory varchar2(30) := 'ORADIR';
   l_filename varchar2(30) := 'text_file.txt';
   l_outfile utl_type.file_type;
   l_buffer varchar2(32767);
   
begin
   l_outfile := utl_file.fopen(l_directory, l_filename, 'r');

   if utl_file.is_open(l_outfile) = false
   then
      l_outfile := utl_file.fopen(l_directory, l_filename, 'r');
   end if;
   
   --gets file from the text file...
   utl_file.get_line(l_outfile, l_buffer);
   
   --write data from text file
   dbms_output.put_line(l_buffer);
   
   --close file.
   utl_file.fclose(l_outfile);   

end;

=================================================

so the catch here is how am i going to implement the loop in order to read the multiple record with "D" at the beginning of the record. i've tried using loop but didn't work i only got 1 row of record. what appears with my dbms_output.put_line is "H00001XXXXX888888". i want to display all the text file so i could get the data from the text file and insert it in the table.

thanks guys :)

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2009
Added on Jan 26 2009
3 comments
718 views