data e.g. (Date, server, n1, n2, command) 20141201 00:00:01, sun_solaris, 30308, 0.0, "sun_gen0_db1 " 20141201 00:00:10, hp_host, 30308, 0.0, "[(jdbc/migration] -/^perl " #!/usr/bin/perl use warnings; use strict; use Text::CSV; use DBD::Oracle; my $exitStatus = 0; # Connect to database and disable autocommit my $dbAgent = OracleAgent->dbLogin(dbName); $dbAgent->connect(); $dbAgent-> setAutoCommit(0); # 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) { $logFile-> ("Working under: $file"); &insertRecords; } $logFile-> ("Exit status") #---------------- sub insertRecords { my $csv; my $fileToInsert = shift; my $row; my $SQL; my $sth; my $dbh; my $rc; open my $fh, "<", $fileToInsert or die "$filetoInsert: $!" $logFile -> ("Working under $file") my $csv = Text::CSV->new ( { binary =>1, auto_diag =>1, allow_loose_quotes =>1, allow_white_space =>1, }); $SQL1 = "Insert into TAB1 (sample_date, server, n1, n2, command) values (?,?,?,?,?)"; $sth = prepare($SQL1); while ($row = $csv->getline ($fh)) { $sth -> execute($row[0], $row[1], $row[2], $row[3], $row[4]); if ($sth1->err) { my $status = "FAIL"; last; } $rc++; } if $status eq 'FAIL' { $dbAgent->rollback(); $rc=0; } else $dbAgent-> commit; close $fh; } }