2 u011605971 u011605971 于 2016.04.11 10:55 提问

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 ;
 错误代码: 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 '_id, _content;
    DEALLOCATE PREPARE stmt;
END' at line 7

3个回答

u011605971
u011605971   2016.04.11 12:53
已采纳

查找官方问道找到答案了,USING只能接user variable

http://dev.mysql.com/doc/refman/5.6/en/execute.html

action_puke
action_puke   2016.04.11 11:36

双-- 就是将其注释掉了 ,所以数据库缺少'_id, _content;

CSDNXIAOD
CSDNXIAOD   2016.04.11 12:05

MySQL错误,存储过程死循环错误
Mysql 存储过程 不存在错误
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!