简体   繁体   中英

Why is this a SQL syntax error?

I have this query in Perl:

my $pkg="%";
my $sql = "SELECT pid, CAST(pid as UNSIGNED) AS l FROM xmld ORDER BY l WHERE pkg LIKE ?";
my $files_ref = $dbh->selectcol_arrayref($sql, undef, $pkg); 

It crashes with:

DBD::mysql::db selectcol_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE pkg LIKE '%'' at line 1 at ...

I have been looking at this statement for hours, tried various things, but no luck. Where is that extra single quote coming from and how do I get rid of it?

order by goes after the where :

SELECT pid, CAST(pid as UNSIGNED) AS l
FROM xmld
WHERE pkg LIKE ?
ORDER BY l;

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