Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

How can I store Sql query result in variable in perl?

I am executing following SELECT query from my perl program and I am using DBI interface
my $test=$dbh->prepare("SELECT AVG(diff) FROM data WHERE key1='s' and key2='i'");
$test-> execute();

The above query , if executed in SQL query browser generate average result of column 'diff' which I want to store in variable in perl for further use

I have idea of dump_results function provided by DBI as one of the option but doesn't seems to work for me
0
saini_er
Asked:
saini_er
  • 2
1 Solution
 
UmeshMySQL Principle Technical Support EngineerCommented:
Try this..

@row = $sth->fetchrow_array();
 
$myVar = $row[0];

Open in new window

0
 
UmeshMySQL Principle Technical Support EngineerCommented:
oops...try this..

@row = $test->fetchrow_array();
 
$myVar = $row[0];
0
 
saini_erAuthor Commented:
Thanks a lot .it worked like a charm
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now