简体   繁体   English

mysql 变量声明的语法错误

[英]syntax error for mysql declaration of variable

CREATE PROCEDURE dorepeat(IN p1 INT)
BEGIN
  DECLARE x INT DEFAULT 0;
  REPEAT SET x = x + 1; UNTIL x > p1 END REPEAT;
END

I get an syntax error:我收到一个语法错误:

#1064 - 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 '' at line 3

But for me, everything seems to be correct.但对我来说,一切似乎都是正确的。 i really don't have any clue!我真的一点头绪都没有! can anybody help?有人可以帮忙吗?

thanks谢谢

You need to temporarily change the delimiter so the MySQL client doesn't think you're done with your statement when it sees the semicolon on line 3:您需要临时更改分隔符,以便 MySQL 客户端在看到第 3 行的分号时不会认为您已经完成了您的语句:

DELIMITER //

CREATE PROCEDURE dorepeat(IN p1 INT)
BEGIN
  DECLARE x INT DEFAULT 0;
  REPEAT SET x = x + 1; UNTIL x > p1 END REPEAT;
END//

DELIMITER ;

Remove the DECLARE, you should be able to just do this:删除 DECLARE,您应该可以这样做:

SET @x = 0;

Also, variables need to be prefixed with the @ symbol此外,变量需要以@符号为前缀

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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