简体   繁体   中英

SQL error in DBI module in perl


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";  
}

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM