Thursday, September 13, 2007

Import delimited file into DB

At first I was a lil worried about how I was going to make this happen at the command line. I am very comfortable with the command line, but it's been a while since I've used perl or other suitable languages. I had _no idea_ how I could possibly get a delimited file from the command line (in a script run as a cron) into Oracle, so I set that aside, and opted for MySQL.

First I wrote a script in perl. Just a quickie, to make sure i'd be able to ftp down the file, and insert it into MySQL. No luck.. none of the ability to connect to MySQL. *snap*.
Route two was to try and use the LOAD DATA LOCAL INFILE commands in MySQL.. I couldn't seem to get it working at the command line.. no idea why, but I then went down another path.
Route three I found that PHP on the servers was CLI version! WOOT! Since PHP and I are most firmly aquainted, I wrote a quick script, also trying the LOAD DATA path. Some luck, but wasn't doing everything I wanted.

Final Route is just a good old read file and an explode, followed by a loop with an insert statement. Easy as pie.

Now I think I might have to use Oracle after all. Don't tell my boss ;)

BFN!

2 comments:

Anonymous said...

hi Jeni.
Good blog.

Regarding the projects you are working on, here are someltools and things that might be interesting to you at some time:

http://www.sobolsoft.com/oracleimporrest/

http://withdata.com/oracmd.html

Or just bump up a level to the main domain for a bunch of little goodies that could oome in handy for something some time.

Ok take care,

-SGC

:-)

Unknown said...

Thanks!!