after some research decided to put question here for more expert answers.Couldn't find exact scenario as my problem so here it goes...
I think it will take few days for me to get something working, can't even think about how to move forward now.
DB: 11gR2
OS: Unix
I'm trying to load multiple csv file into Oracle table using perl script.
List what all csv I need to work on, since directory where csv file exist contains many other files.
Open csv file and insert into table
If there are any error then rollback all inserts of that file and move into next file
Record how many inserts done by each file
#!/usr/bin/perl use warnings; use strict; use Text::CSV; use DBD::Oracle; my $exitStatus = 0; my $dow = `date +%a`; chomp $dow; my $csvDow = `date -dd +%a`; chomp $csvDow; # define logfile my logFile; $logFile = "log.dbinserts" # define csv file directory my $csvLogDir = "Home/log/$csvDow"; # csv Files in array to list all possible match of file opendir(my $dh, $csvLogDir ) || die "can't opendir $csvLogDir : $!"; my @csvFile = grep { /csv.*host1/ && -f "$csvLogDir/$_" } readdir($dh); chomp @csvFile; closedir $dh; foreach my $i (@csvFile) { $logFile (CSV File: $i); } foreach my $file (@csvFile) { chomp ($item); $logFile-> ("Working under: $file"); &insertRecords($csvLogDir."/".$file); } $logFile-> ("Exit status") #---------------- sub insertRecords { my $filetoInsert=shift; my $row; open my $fh, "<" or die "$fileToInsert: $!"; my $csv = Text::CSV->new ({ binary =>1, auto_diag =>1, }); while ($row = $csv->getline ($fh)) { print "first column : $row->[0]\n,"; } close $fh; } ======== CSV File ========= date, host, first, number1, number2 20141215 13:05:08, S1, John, 100, 100.20 20141215 13:06:08, S2, Ray, 200, 200.50 ... ... ... ========= Table - tab1 ========= Sample_Date Server First N1 N2
use warnings&use strict. Beyond that you seem to have a strange blend of Perl 4 & shell scripting here. Gotta leave now, but if you haven't received an answer by the time I get back, I'll start addressing your many needs.