zoukankan      html  css  js  c++  java
  • 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..
    ";
    my $sth = $dbh->prepare($sql);
    print "$sth is $sth..
    ";
    
    $sth->execute();
    my $count = $sth->fetchrow_array();
    print "$count is $count....
    ";
    if ( $count  ){
    print "not empty";}
    else {print "empty
    "}
    $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
    ";}
    else {print "empty
    "}
    
    [oracle@jhoa ~]$ perl a2.pl 
    empty
    
    [oracle@jhoa ~]$ cat a2.pl 
    my $count = 2;
    if ( $count  ){
    print "not empty
    ";}
    else {print "empty
    "}
    
    [oracle@jhoa ~]$ perl a2.pl 
    not empty
    

  • 相关阅读:
    C#深入浅出 修饰符(二)
    HDU 5785 Interesting
    HDU 5783 Divide the Sequence
    HDU 5781 ATM Mechine
    UVA 714 Copying Books
    uva 1471 Defense Lines
    UVA 11134 Fabled Rooks
    UVA 11572 Unique Snowflakes
    UVA 11093 Just Finish it up
    UVA 10954 Add All
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352081.html
Copyright © 2011-2022 走看看