当前位置:Gxlcms > mysql > mysql-MySQL:为什么这样的小改动会造成存储过程错误呢?

mysql-MySQL:为什么这样的小改动会造成存储过程错误呢?

时间:2021-07-01 10:21:17 帮助过:37人阅读

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

人气教程排行