MySQL版本:5.7

问题:
[Err] 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 'DECLARE userName VARCHAR(20)

解决:
需将DECLARE 放在在存储过程、函数或者触发器中,再调用它(call 函数名或存储过程名)
例:
CREATE PROCEDURE procd1()
BEGIN
DECLARE userName VARCHAR(20);
DECLARE userEmail VARCHAR(20);
DECLARE i INT DEFAULT 4;
WHILE i<= 400 DO
set userName = CONCAT(‘test’,LPAD(i,3,‘0’));
set userEmail = CONCAT(‘userName’, ‘@test.com’);
INSERT INTO jforum_users(user_id,user_active,username,user_password,user_regdate,user_email) VALUES(i,
‘1’, userName,‘abcd1234’, ‘2021-05-10 06:19:34’, userEmail);
INSERT INTO jforum_user_groups VALUES(3,i);
SET i = i+1;
END WHILE;
END

最后执行procd1:call procd1

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐