in reply to Re^2: Calling a plsql file from perl script
in thread Calling a plsql file from perl script
Note that I've used a single query with placeholders rather than interpolation of values. This is both more efficient and protects you from SQL-injection and escaping issues. I've also taken advantage of the fact that 1 is true in Perl, thus bypassing an equality check. Finally, I explicitly included my target fields in the INSERT, since this makes you resilient to schema changes and makes maintenance more obvious.use strict; use warnings; use DBI; my $db = DBI->connect( $dbid, $user, $password, { PrintError => 0, RaiseError => 1, AutoCommit => 0, }, ); my $query = $db->prepare(<<EOSQL); INSERT INTO temp (field1, field2, field3) VALUES(?, ?, ?) EOSQL my $x = 100; for my $i (1 .. 10) { $query->execute($i, $x, $i % 2 ? 'i is odd' : 'i is even'); $x += 100; } $db->commit;
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|