I'm trying to put logic into perl coding but not able to do so for sometime now.
What I'm trying to do is1. Open csv file
2. Insert line into Oracle table
3. If any error then
3.1 Rollback all inserts of the file
3.2 Update status table with FAILURE
3.3 Move to next file
4. If all inserts completed then
4.1 Update status table with SUCCESS
5. Commit
Could some expert monks help me out sorting this logic?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); #@csvFile holds all csv files list to load in db foreach my $file (@csvFile) { chomp ($item); &insertRecords($file); } $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") while ($row = $csv->getline ($fh)) { $SQL1 = "Insert into TAB1 (sample_date, server, first, n1, n2) values (?,?,?,?,?)"; $sth = prepare($SQL1) $sth -> execute($row[0], $row[1], $row[2], $row[3], $row[4]) || { logFile($DBI::errstr); $dbAgent->rollback; $rc=0; #if error in insert then update status table $SQL3 = "Insert into STATUS (sample_date, server +, cvs_file, row_count, status) values (sysdate,$row[1],$file,$rc,'FAI +LURE')"; $sth = executeQuery($SQL3); } else { #if no error in insert then update status table an +d commit everything $SQL2 = "Insert into STATUS (sample_date, server, + cvs_file, row_count, status) values (sysdate,$row[1],$file,$rc,'SUCCESS')"; $sth = executeQuery($SQL2); $rc++; } close $fh; $dbAgent->commit;
In reply to Perl oracle insert error handling by homer4all
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |