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
'DECLARE @nCnt int, @Sno varchar(20),@Sname varchar(20) set @nCnt = 1 while @nCnt' at line 1 0.000 sec
mysql只能在存储过程或者函数内申明变量的,和sqlserver不一样
DECLARE 只用于存储过程中。
用户定义变量(User variables),也就是题目中名字以 @开头 的变量,不能用DECLARE声明。
在存储过程中声明变量的语法为:
DECLARE variable_name datatype(size) DEFAULT default_value;
下面是一个例子:
DECLARE total_count INT DEFAULT 0;
SET total_count = 10;
再举一个例子:
DECLARE total_products INT DEFAULT 0
SELECT COUNT(*) INTO total_products
FROM products