Link to home
Start Free TrialLog in
Avatar of saibsk
saibsk

asked on

Returning a single value from resultset in Perl DBI

My result set is going to return only one value from the database. I am connecting to the DB using perl dbi. How shd i fetch the value? Please advise.
ASKER CERTIFIED SOLUTION
Avatar of Carl Bohman
Carl Bohman
Flag of United States of America 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 michaelshavel
michaelshavel

Do you have some code that you've already tried but doesn't work? If so, post it here please.

Mike
You can use prepare/exectue/fetch as shown by bounsy, or you can just use one of the selectrow methods, which does all of these at once.
#Get data as array
my @record = $dbh->selectrow_array('SELECT ....');
 
#Get data as arrayref
my $record = $dbh->selectrow_arrayref('SELECT ....');
 
#Get data as hashref
my $record = $dbh->selectrow_hashref('SELECT ....');

Open in new window