Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl DBI question.....

Status
Not open for further replies.

huskers

Programmer
Jan 29, 2002
75
US
Hi,

I want to add a value to an already existing data in the table. For ex:

Table A:
a b c
10 20 30
40 50 60

I want to add 50 to column a and column b so that the result looks like this:
Table A:
a b c
60 70 30
90 100 60

Can anyone tell me if i can acheive this using one sql statement in perl DBI.

Thanks
 
untested code general idea

my $dbh = DBI->connect( undef, undef, undef, { RaiseError => 1});

my $sth = $dbh->prepare("SELECT a,b,c FROM a");
$sth->execute();
my $array_ref = $sth->fetchall_arrayref();

foreach my $row (@$array_ref) {

my (@data) = @$row;

foreach (@data){
$_ = $_ + 50;
}
($a,$b,$c) = @data;

$sql = qq(UPDATE a SET a = $a, b = $b, c = $c);
$sql->execute();
}

$dbh->disconnect();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top