#!perl -n ## Example use: ## ./bulk-upload.pl user/pass@sid table cola colb < bulk-file use strict; use vars qw!$table @columns $dbh $sth!; BEGIN { use DBI; $dbh = DBI->connect("dbi:Oracle:", shift, '', { 'AutoCommit' => 'false' }); $table = shift; @columns = @ARGV; $sth = $dbh->prepare( "insert into $table (", join(",", @columns), ") values (", join(",", ("?") x @columns), ")" ); } my @values = split /\t/, $_; unless ($sth->execute(@values)) { print "Failed on line $., values @values: " . $dbh->errstr; }; END { $dbh->commit }
Important caveats: