前端之家收集整理的这篇文章主要介绍了
perl select count(*) 返回0条,为假判断,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/usr/bin/perl
use strict;
use DBI;
my $dbName = 'orcl';
my $dbUser = 'test';
my $dbUserPass = 'test';
my $dbh = DBI->connect("dbi:Oracle:$dbName",$dbUser,$dbUserPass) or die "can't connect to database " ;
my $sql = "select count(*) from a11";
print "\$sql is $sql..\n";
my $sth = $dbh->prepare($sql);
print "\$sth is $sth..\n";
$sth->execute();
my $count = $sth->fetchrow_array();
print "\$count is $count....\n";
if ( $count ){
print "not empty";}
else {print "empty\n"}
$sth->finish;
$dbh->disconnect;
[oracle@jhoa ~]$ perl dbi.pl
$sql is select count(*) from a11..
$sth is DBI::st=HASH(0x2df1db0)..
$count is 0....
empty
0在perl里为假:
[oracle@jhoa ~]$ cat a2.pl
my $count = 0;
if ( $count ){
print "not empty\n";}
else {print "empty\n"}
[oracle@jhoa ~]$ perl a2.pl
empty
[oracle@jhoa ~]$ cat a2.pl
my $count = 2;
if ( $count ){
print "not empty\n";}
else {print "empty\n"}
[oracle@jhoa ~]$ perl a2.pl
not empty