MySQL在创建存储过程的时候,语法正确却提示You have an error in your SQL syntax
2014-04-15 15:00
633 查看
我在使用MySQL工具编写MySQL存储过程的时候,明明语法正确,但是却一直提示You have an error in your SQL syntax。
比如下面一段代码
找了半天才找到解决方案,原来不是语法的错误,是MYSQL语法解析器的原因。MYSQL 解析器解析遇到“;”分号,就结束本次执行,所以就造成了很多语法错误。解决方案是:
比如下面一段代码
CREATE PROCEDURE demo_pro() BEGIN DECLARE doned BOOLEAN; DECLARE addr varchar(20); DECLARE demo_cur CURSOR FOR SELECT detail from address; DECLARE CONTINUE HANDLER FOR NOT FOUND SET doned = True; SET doned = False; OPEN demo_cur; demo_cur:LOOP FETCH demo_cur into addr; IF doned THEN LEAVE demo_cur; ELSE insert into demo(demo_value) values(addr); END IF; END LOOP; CLOSE demo_cur; END;
找了半天才找到解决方案,原来不是语法的错误,是MYSQL语法解析器的原因。MYSQL 解析器解析遇到“;”分号,就结束本次执行,所以就造成了很多语法错误。解决方案是:
DELIMITER | #结束符号,可以根据自己的需求,改成 $也可以 CREATE PROCEDURE demo_pro() BEGIN DECLARE doned BOOLEAN; DECLARE addr varchar(20); DECLARE demo_cur CURSOR FOR SELECT detail from address; DECLARE CONTINUE HANDLER FOR NOT FOUND SET doned = True; SET doned = False; OPEN demo_cur; demo_cur:LOOP FETCH demo_cur into addr; IF doned THEN LEAVE demo_cur; ELSE insert into demo(demo_value) values(addr); END IF; END LOOP; CLOSE demo_cur; END;| DELIMITER ;
相关文章推荐
- 创建存储过程错误(已解决):Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ver
- mysql 存储过程中limit(#1064 You have an error in your SQL syntax)
- 报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL
- 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
- SpringMVC:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax;
- SQL Error: 1064, SQLState: 42000 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
- 误用关键字-_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax;
- ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
- java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL se
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- mysql sqlserver hibernate 有数据库关键字 You have an error in your SQL syntax; check the manual that corres
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- Hibernate操作MySQL使用reserved word引发错误: “You have an error in your SQL syntax; check the manual that co
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version