Link to home
Start Free TrialLog in
Avatar of deNZity
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:wdat2ghw', '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
ASKER CERTIFIED SOLUTION
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deNZity
deNZity

ASKER

Thanks for the reply, I wondered wether or not I needed to prepare and execute
the sql.
I used ('$result[0]','$result[1]')";

points to you.
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}.