On Apr 30, 2010, at 1:26 PM, Parag Kalra wrote:

I am executing simple insert SQL queries in a loop

I have a simple requirement - While insert quieries are being executed, if any error occurs it should print that message and move to next insert sql
query. I am using DBD::Oracle on Unix

Try this instead of using $dbh->do().

(This presumes that $dbh is your working database handle, and the arrays @name, @address, @email, @custid are the arrays holding your data to be inserted into the table. $i is the number of rows you're inserting.)

$sqinsert = "Insert into foo (name, address, email, custid) values(?,?,?,?)";

$csr= $dbh->prepare($sqinsert);
        if($ora_errstr) {print "$ora_errstr happened with $sqinsert";}
        #this catches errors in the sql

for ($n=0;$n<$i;$n++){
        $csr->execute($name[$n],$address[$n],$email[$n],$custid[$n]);
if($ora_errstr) {print "$ora_errstr happened with data values $name[$n],$address[$n],$email[$n],$custid[$n]";}
        }

I JUST did something similar yesterday dumping some data into our oracle database.

Heck, even if you don't trap the error with "if ($ora_errstr)..." Oracle DBI doesn't stop the script, it just doesn't work, and goes to the next statement.

--
Bruce Johnson
University of Arizona
College of Pharmacy
Information Technology Group

Institutions do not have opinions, merely customs


Reply via email to