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

问题描述

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

解决方案

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

解决方案二:

MySQL错误,存储过程死循环错误
Mysql 存储过程 不存在错误

解决方案三:

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

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

时间: 2024-12-01 14:22:54

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

Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/mysql.pid).

  mysql重启导致出现以下错误:      Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/mysql.pid).             删除ibdata1.ib_logfile* 相关文件   删除之前先备份     使用命令重启:           /usr/local/mysql/support-files/mysql.server start --user=mysql --

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

从供应商手中接手一个云平台(Windwos Azure)上的MySQL数据库,登录数据库时遇到错误: $mysql -uroot -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 检查配置文件/etc/my.cnf发现供应商修改了mysql数据库的数据存储目录,另外mysql.sock文件位置也变更为了/

Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

   mysql 突然访问不了,登上服务器发现,mysql进程不见了.            错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)       发现是权限问题导致的.           改变权限 #chown -R mysql:mysql /var/lib/mysql            [root@localhost

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (

mysql启动成功 service mysqld start  mysql is OK mysql登录错误 : [root@localhost ~]# mysql -uroot -p123456ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 解决: vim /etc/my.cnf 找到 socket路径 scoket=/tmp/mysql.

这个Oracle语句转成 mysql语句怎么写 ,我每次运行都有错误

问题描述 这个Oracle语句转成 mysql语句怎么写 ,我每次运行都有错误 2C select * from (select rownum rng.*c.name cname from shop_goods gshop_category c where g.categoryid=c.id and g.categoryid=#{categoryid} and g.name like #{name} ) r where r.rn between (#{page}-1)*#{pageSize} a

connection to dat Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[root@t1 ~]# tail /tmp/zabbix_server.log  23392:20160303:131022.598 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)  23392:20160303:131022.598 Database is down.

php-[PHP] wamp环境下。使用PDO连接mysql,能执行查询的sql,不能调用存储过程

问题描述 [PHP] wamp环境下.使用PDO连接mysql,能执行查询的sql,不能调用存储过程 $sql='CREATE PROCEDURE t7() select * from tb_article '; $dbh=new PDO($dsn, 'lms', '123456'); $stmt=$dbh->query('CALL t1()'); // $stmt=$dbh->prepare('CALL t1()'); // $stmt->execute(); if($stmt){ $

MYSQL错误解决:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 据说这个问题的原因很多,当然,我自己这个问题我是清楚的,就是mysql.sock的位置所致,一个是PHP要求的,一个是MYSQLD定义的,一个是MY.CONF指定的...SO.... 暂时不能统一的话,用软链接LN -S命令解决吧..   方案5      摘要:解决不能通过mysql .so

debian下安装mysql mysql是.DEB后缀的文件包

问题描述 debian下安装mysql mysql是.DEB后缀的文件包 debian linux 操作系统下安装mysql数据库 mysql数据库的文件包是以.DEB结尾的 求安装方法 解决方案 http://www.2cto.com/database/201305/212200.html