Solved

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

Posted on 2008-11-02
3
449 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now