deNZity
asked on
insert multiple rows using while loop
I would like to insert multiple rows into oracle table.
script runs and completes no error messages but it doesnt do the insert.
use DBI;
use strict;
#create connection
my $wdat2ghw = DBI->connect('DBI:Oracle:w dat2ghw', 'student', 'learn')
|| die "Database connection not made: $DBI::errstr";
#create and execute query
my $strsql = "select employee_id, name from employee";
my $result = $wdat2ghw->prepare($strsql );
$result->execute or die "Couldn't execute: " . $wdat2ghw->errstr . "\n";
my @result = $result-> fetchrow_array;
while(@result = $result->fetchrow_array){
#insert 1 record
"insert into customer (customer_id, name) values ('@result')";
};
$result->finish;
$wdat2ghw->disconnect;
print "All done";
D
script runs and completes no error messages but it doesnt do the insert.
use DBI;
use strict;
#create connection
my $wdat2ghw = DBI->connect('DBI:Oracle:w
|| die "Database connection not made: $DBI::errstr";
#create and execute query
my $strsql = "select employee_id, name from employee";
my $result = $wdat2ghw->prepare($strsql
$result->execute or die "Couldn't execute: " . $wdat2ghw->errstr . "\n";
my @result = $result-> fetchrow_array;
while(@result = $result->fetchrow_array){
#insert 1 record
"insert into customer (customer_id, name) values ('@result')";
};
$result->finish;
$wdat2ghw->disconnect;
print "All done";
D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to help, yes my error, result[1] is correct. You can also fetch into a hash and the used named parameters like $result{employee_id}.
ASKER
the sql.
I used ('$result[0]','$result[1]'
points to you.