Solved

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

Posted on 2008-11-02
3
472 Views
Last Modified: 2012-06-21
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
Comment
Question by:saini_er
  • 2
3 Comments
 
LVL 26

Expert Comment

by:ushastry
ID: 22864908
Try this..

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

Open in new window

0
 
LVL 26

Accepted Solution

by:
ushastry earned 500 total points
ID: 22864911
oops...try this..

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

Author Closing Comment

by:saini_er
ID: 31512593
Thanks a lot .it worked like a charm
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question