Inserting records from flat file to db table

I have 20000 numbers present in a file in each line like

25663,
65465,
74579,
56446,
..
..

I have created a table in db with single number column in it.

create table testhari (no number(9));

I want to insert all these numbers into that table. how can i do it?

can anybody please help..

Please don't suggest to loop 20000 times and connect to db each time using sql plus.. using "while read line do .. done"

Whats wrong with the while read line ?!? :smiley: :smiley:
Anyway, since you mention sqlplus im guessing you work with oracle database which is good since it has feature designed for that kind of task 'sqlldr'

sqlldr yourdbacctname control=input.ctl log=haritest.log

the content of input.ctl

load data 
infile thefilewithno 
into table testhari (no)

what database you are using?

use sqlldr.

Eg:

LOAD DATA INFILE * APPEND INTO TABLE <<Tablename>> FIELDS TERMINATED BY "," TRAILING NULLCOLS
(<<fieldname>> INTEGER EXTERNAL)

make it as file.ctl

and then use sqlldr like this

${ORACLE_HOME}/bin/sqlldr userid=${USERPASS} control=<<path>>/file.ctl log=<<path>>/<<filename>>.log data=<<path>>/<<20000filename>> errors=1000 &

Worked pretty good.. thanks a lot Mr.kumar

Sorry, i ve not mentioned my database ie ORACLE.

Problem with while read line is
For me, connecting to db each time is very expensive using sqlplus.. And i can't even imagine it for 20000 times.. Anyways.. thanx a lot for sqlldr option

I also like to share one freeware for loading excel data into oracle.(Oracle 9i+)
Download the exe from http://www.oraxcel.com

As your data is comma separated u can open it excel
and can play with the data.

I hope this might be a very good link.

:slight_smile:

Regards,
cskumar.