Perl 中 DBI 模块中的 SQL 错误

发布于 2024-10-31 14:31:17 字数 822 浏览 3 评论 0原文


当我运行此查询时,我没有得到任何输出。我无法弄清楚。任何人都可以帮助我吗?在本例中,$lastfiscyear = 09/10。

getitem44();  
sub getitem44()  
{  
$sqlquery = sprintf("select sum(f.expenditure)          
                     from funds f,ledger l      
                     where l.ledger_id in (select ledger_id from ledger  
                                           where upper(ledger_name) like 'MONOACQ%' and  
                                           substr(ledger_name,length(ledger_name)-4, 5) = '%s') and  
                                  f.ledger_id = l.ledger_id and  
                                  substr(f.funds_name, 1, instr(f.funds_name,',')-1) like '%e' ", $lastfiscyear);    
$sth = $dbh->prepare($sqlquery);  
$rc = $sth->execute;  
my $total = $sth->fetchrow_array;  
print "$total\n";  
}

I was not getting any output when I run this query. I was not able to figure it out.Can anyone please help me. $lastfiscyear = 09/10 in this case.

getitem44();  
sub getitem44()  
{  
$sqlquery = sprintf("select sum(f.expenditure)          
                     from funds f,ledger l      
                     where l.ledger_id in (select ledger_id from ledger  
                                           where upper(ledger_name) like 'MONOACQ%' and  
                                           substr(ledger_name,length(ledger_name)-4, 5) = '%s') and  
                                  f.ledger_id = l.ledger_id and  
                                  substr(f.funds_name, 1, instr(f.funds_name,',')-1) like '%e' ", $lastfiscyear);    
$sth = $dbh->prepare($sqlquery);  
$rc = $sth->execute;  
my $total = $sth->fetchrow_array;  
print "$total\n";  
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强者自强 2024-11-07 14:31:17

您需要使用额外的百分号对 %e 进行转义,否则 sprintf 会将其解释为转换说明符(科学记数法中的浮点数)。

sprintf "select sum(f.expenditure) ... like '%%e' ", $lastfiscyear;

有关详细信息,请参阅 perldoc sprintf

You need to escape %e with an additional percent sign because otherwise sprintf interprets it as a conversion specifier (a floating-point number in scientific notation).

sprintf "select sum(f.expenditure) ... like '%%e' ", $lastfiscyear;

See perldoc sprintf for details.

夜巴黎 2024-11-07 14:31:17

请注意,sprintf 将使用 % 符号作为占位符。如果你想将 % 逐字放入字符串中,请将其加倍。我认为问题是 %e 接近尾声 - 它被替换为 0.000000e+000

Please note that sprintf will use % sign for placeholders. If you want to put verbatim % into string, double it. I think the problem is %e close to the end - it is replaced with 0.000000e+000.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文