Christopher G Tantalo [[EMAIL PROTECTED]] wrote:
> Stephane Legault wrote:
>
> > I do a lot of select in many statement and fetch the result on a array as
> > needed. But now one of my staement is a "select count() from ...". How can
> > I get the value of this statement?
>
> I do not know what db you are using, etc, but here we are using oracle on a
> *nix box. and it is just the same as any other db call
> my $sth = $dbh->prepare("SELECT count(*) from dmg.papf_view")
> or die "Cant prepare SQL statement: $DBI::errstr\n";
my $sql = qq{
SELECT count(*)
FROM my_table
};
my $sth = $dbh->prepare($sql)
or die "Can't prepare SQL statement: $DBI::errstr";
$sth->execute() or die "Can't execute SQL statement: $DBI::errstr";
### Need the parenthesis arround $total_rows here since
### we're using fetchrow_array.
my ($total_rows) = $sth->fetchrow_array()
I didn't use a while loop here since you're only expecting
1 row to be returned - that being the count.
That's the basic concept - off-the-top-of-my-head I can't remember
what fetchrow_array returns if there is an error or if there
are no rows - you'll need to check for those conditions.
HTH.
--
Hardy Merrill
Senior Software Engineer
Red Hat, Inc.