Skip to Main Content

Portuguese

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!

UTL_FILE to read a textfile and load in table :

itzkashiDec 12 2015 — edited Oct 18 2018

Hi ,

i have created a file 'writefile' using below and it is created  successfully.

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

declare

  ltype utl_file.file_type;

  ldir  varchar2(100) := 'DATA_PUMP_DIR';

  lfile  varchar2(100) := 'writefile.sql';

  s varchar2(10) := ',';

begin

  ltype := utl_file.fopen(ldir,lfile,'w');

  for i in (select * from emp)

    loop

      utl_file.putf(ltype,i.empid||s||i.sal);

      UTL_FILE.NEW_LINE(ltype);

    end loop;

  utl_file.fclose(ltype);

end;

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

out put <writefile.sql>

184,4200

185,4100

186,3400

....

i have created a new table tmp with empid and first_name columns, could you please let me know how could i read this file and load the data into new table tmp ...

i tried using this but its not working..

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

declare

f UTL_FILE.FILE_TYPE;

ldir varchar2(100) := 'DATA_PUMP_DIR';

lfile varchar2(100) := 'writefile.sql';

s VARCHAR2(200);

BEGIN

f := UTL_FILE.FOPEN(ldir,lfile,'R');

  IF UTL_FILE.IS_OPEN(f) THEN

    LOOP

      BEGIN

        UTL_FILE.GET_LINE(f,lfile);

        IF lfile IS NULL THEN

          EXIT;

        END IF;

      INSERT INTO tmp

      (empid, first_name)

      VALUES

      ( );

      END;

  END LOOP;

  COMMIT;

  END IF;

END;

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

This post has been answered by Alex.Zaballa on Dec 13 2015
Jump to Answer

Comments

Processing

Post Details

Added on Dec 12 2015
5 comments
70,129 views