Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: DBD::ORacle: Not able to insert into Database

by slayedbylucifer (Scribe)
on Jul 30, 2012 at 08:40 UTC ( #984391=note: print w/ replies, xml ) Need Help??


in reply to Re^3: DBD::ORacle: Not able to insert into Database
in thread DBD::ORacle: Not able to insert into Database

mje, here is my code after following your suggestions.

sub upload { my ($csv_file, $table, $col1, $col2, $col3) = ($_[0], $_[1], $ +_[2], $_[3], $_[4]); my $csv = Text::CSV->new ( { binary => 1 } ) or die "Cannot us +e CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", $csv_file or die " $!"; <$fh>; ### this is to remove the column headers. my $dbh = DBI->connect ("dbi:Oracle:host=<hostname>t;sid=SID;p +ort=1526", 'username', 'password', { RaiseError => 1, AutoCommit => 1, Tr +aceLevel => 0 }) or die "Cannot create Database Handle: + $DBI::errstr()"; my $sth = $dbh->prepare ("INSERT INTO $table ($col1, $col2, $c +ol3) VALUES (?,?,?)"); while ( my $row = $csv->getline ($fh)) { $sth->execute ($row->[0], $row->[1], $row->[2]); } $sth->finish(); $dbh->disconnect(); close $fh; }

Thank you very much for guiding me.


Comment on Re^4: DBD::ORacle: Not able to insert into Database
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://984391]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (16)
As of 2015-07-01 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (9 votes), past polls