首页 新闻 会员 周边

mysql 定义条件时候报错"server version for the right syntax to use near '' at line 3"

0
[待解决问题]

/第一段执行没问题/
CREATE TABLE test.t (sl INT,PRIMARY KEY (sl));
DELIMITER //
/第二段执行报错,/
CREATE PROCEDURE handlerdemo ()
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET @x2 = 1;
SET @x = 1;
INSERT INTO test.t VALUES (1);
SET @x = 2;
INSERT INTO test.t VALUES (1);
SET @x = 3;
END;
//

ps:报错
错误代码: 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 '' at line 3

执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

查询:set @x = 1

共 0 行受到影响

执行耗时 : 0.037 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

查询:insert into test.t values (1)

错误代码: 1062
Duplicate entry '1' for key 'PRIMARY'

执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

查询:set @x = 2

共 0 行受到影响

执行耗时 : 0.037 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

查询:insert into test.t values (1)

错误代码: 1062
Duplicate entry '1' for key 'PRIMARY'

执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

查询:set @x = 3

共 0 行受到影响

执行耗时 : 0.037 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

查询:end

错误代码: 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 'end' at line 1

执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

查询://

错误代码: 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 '//' at line 1

执行耗时 : 0 sec
传送时间 : 0 sec
总耗时 : 0.037 sec

孟许的主页 孟许 | 菜鸟二级 | 园豆:206
提问于:2021-11-30 16:16
< >
分享
所有回答(1)
0

你的 SQL 语法有错误; 检查与您的 MySQL 服务器版本相对应的手册,以获取在第 3 行的 '' 附近使用的正确语法

中华鲟3670 | 园豆:847 (小虾三级) | 2021-11-30 17:05

这个我知道,mysql5.7版本的,按理说 都没问题。

支持(0) 反对(0) 孟许 | 园豆:206 (菜鸟二级) | 2021-11-30 17:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册