Perl 中 DBI 模块中的 SQL 错误
当我运行此查询时,我没有得到任何输出。我无法弄清楚。任何人都可以帮助我吗?在本例中,$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用额外的百分号对
%e
进行转义,否则sprintf
会将其解释为转换说明符(科学记数法中的浮点数)。有关详细信息,请参阅
perldoc sprintf
。You need to escape
%e
with an additional percent sign because otherwisesprintf
interprets it as a conversion specifier (a floating-point number in scientific notation).See
perldoc sprintf
for details.请注意,
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 with0.000000e+000
.