perl
  • perl-module
  • 2013-12-23 72 views -1 likes 
    -1

    我想從數據庫mysql中只讀取和打印一條記錄。Select語句應該只返回一條記錄

    #Select backlogs 
    { 
         my $backlog_req = "select id, name, startDate, endDate, parent_id " . 
                   " from backlogs " ; 
                   "where backlogtype='Iteration' and id = $iteration" ; 
    print "ITERATION_ID : " . $iteration . "\n"; 
         my $sth = $dbh->prepare($backlog_req); 
         $sth->execute() ; 
         $sth->bind_columns(undef, \$backlog_id, \$bl_name, \$bl_sd, \$bl_ed, \$prod_id) ; 
         while($sth->fetch()) { 
           $Backlogs->{ $backlog_id } = { name => $bl_name, start_date => substr($bl_sd, 0, 10), end_date => substr($bl_ed, 0, 10) } ; 
           print "$bl_name ($backlog_id): $bl_sd -> $bl_ed\n"; 
         } 
    

    這將返回所有與Iteration作爲backlogtype的行。我只需要backlogtype作爲Iteration和Id,我通過命令行參數提供。正如我在哪裏指定的那樣。

    回答

    3

    更改此:

    " from backlogs " ; 
    

    這樣:

    " from backlogs " . 
    

    包括在查詢中WHERE -clause。

    此外,您應該將use warnings;添加到腳本的開頭。它會警告你這件事(通過抱怨說你的WHERE條款聲明是Useless use of string in void context)。

    相關問題