mysql-MySQL:为什么这样的小改动会造成存储过程错误呢?
程序员文章站
2022-05-13 11:45:01
...
mysql
DELIMITER $$ USE mysql$$DROP PROCEDURE IF EXISTS demo$$CREATE PROCEDURE demo(_id INT, _content VARCHAR(64)) BEGIN SET @id = _id; SET @content = _content; PREPARE stmt FROM "INSERT INTO blog (id, content) VALUES(?, ?)"; EXECUTE stmt USING @id, @content; DEALLOCATE PREPARE stmt;END$$DELIMITER ;DELIMITER $$
如果改写成如下就会报错:
DELIMITER $$USE mysql$$DROP PROCEDURE IF EXISTS demo$$CREATE PROCEDURE demo(_id INT, _content VARCHAR(64)) BEGIN -- set @id = _id; -- set @content = _content; PREPARE stmt FROM "INSERT INTO blog (id, content) VALUES(?, ?)"; EXECUTE stmt USING _id, _content; DEALLOCATE PREPARE stmt;END$$DELIMITER ;
错误代码: 1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_id, _content; DEALLOCATE PREPARE stmt;END' at line 7
上一篇: Java 实例 - 数字求和运算