MySQL 1064 语法错误,当没有语法错误时
为了保护我的作品,更改了一些名称和内容。
DELIMITER //
CREATE PROCEDURE glt(IN howMany INT)
BEGIN
DECLARE f VARCHAR(32);
DECLARE done INT DEFAULT 0;
DECLARE curs CURSOR FOR SELECT DISTINCT id FROM tpd;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN curs;
DROP TABLE IF EXISTS lt;
CREATE TEMPORARY TABLE lt LIKE tpd;
REPEAT
FETCH curs INTO f;
IF NOT done THEN
INSERT INTO lt SELECT * FROM tpd WHERE id = f ORDER BY TIME DESC LIMIT howMany;
END IF;
UNTIL done END REPEAT;
CLOSE curs;
END
上面的代码在 Linux 机器上给出了以下错误,但在 Mac 机器上却没有,尽管两者都是区分大小写的文件系统并且具有相同的 MySQL 版本:
ERROR 1064 (42000) at line 172: 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 'howMany;
END IF;
UNTIL done END REPEAT;
CLOSE curs;
END' at line 16
Bye
Some names and stuff changed to protect my work.
DELIMITER //
CREATE PROCEDURE glt(IN howMany INT)
BEGIN
DECLARE f VARCHAR(32);
DECLARE done INT DEFAULT 0;
DECLARE curs CURSOR FOR SELECT DISTINCT id FROM tpd;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN curs;
DROP TABLE IF EXISTS lt;
CREATE TEMPORARY TABLE lt LIKE tpd;
REPEAT
FETCH curs INTO f;
IF NOT done THEN
INSERT INTO lt SELECT * FROM tpd WHERE id = f ORDER BY TIME DESC LIMIT howMany;
END IF;
UNTIL done END REPEAT;
CLOSE curs;
END
The above code gives the following error on a linux machine, but not a mac machine despite both being case-sensitive filesystems and having the same MySQL version:
ERROR 1064 (42000) at line 172: 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 'howMany;
END IF;
UNTIL done END REPEAT;
CLOSE curs;
END' at line 16
Bye
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用Prepare语句进行INSERT查询。
看看 http://dev.mysql.com /doc/refman/5.0/en/sql-syntax-prepared-statements.html
看起来看起来像:
Try to use Prepare Statement for INSERT query.
Look at http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html
It seems it will look like:
您不能在此处的
limit
子句中使用参数。您只能在使用 PDO 时执行此操作。在这种情况下,这是一个语法错误。
You cannot use a parameter in the
limit
clause here.You can only do that when using PDO. In this context that's a syntax error.