A couple things:
Those are the only problems I see. However, you might want to rearrange your code to remove the unnecessary array. You can do so like this (untested):
#!/usr/bin/perl -w use strict; use DBI; open (my $FH, '<', "test.csv") or die "Cannot open test.csv: $! \n"; my $dbh = DBI->connect ("dbi:Oracle:host=<hostname>;sid=<SID>", '<username>', ',password.', { RaiseError => 1, AutoCommit => 1, TraceLev +el => 4 } ) or die "Canot create Databse Handle: $DBI::errstr() \n"; my $sth = $dbh->prepare ("INSERT INTO CLUSTER_MAPPING (name, farm, dmz +) VALUES (?,?,?)"); <$FH>; ### this is to remove the column headers while (<$FH>) { my @row = split /,/; my $col1_value = $row[0]; my $var1 = $row[1]; $var1 =~ s/"//g; $var1 =~ s/^ //g; my $col2_value = $var1; my $col3_value = $row[2]; $sth->execute ($col1_value, $col2_value, $col3_value); } # If this is the end of your program, these lines are unnecessary, as +it'll all be # cleaned up at the end of the program. But if you're continuing to d +o something # else in your program, then by all means leave them in. $sth->finish(); $dbh->disconnect(); close $FH;
I also removed the unnecessary variable $table as I couldn't see the purpose for it.
You can do further simplifications, as well. There's no need to create new variables for the columns, you can just operate on the values in place and use them, like so:
while (<$FH>) { my @row = split /,/; $row[1] =~ s/"//g; $row[1] =~ s/^ //g; $sth->execute (@row); }
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: DBD::ORacle: Not able to insert into Database
by roboticus
in thread DBD::ORacle: Not able to insert into Database
by slayedbylucifer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |