MYSQL存储过程中声明变量那句报错了。求高手解答啊
CREATEPROCEDUREBatchInsert(INinitINT,INloop_timeINT)BEGINDECLAREVarINT;DECLAREIDINT;S...
CREATE PROCEDURE BatchInsert(IN init INT, IN loop_time INT)
BEGIN
DECLARE Var INT;
DECLARE ID INT;
SET Var = 0;
SET ID = init;
WHILE Var < loop_time DO
insert into employees(id,fname,lname,birth,hired,separated,job_code,store_id) values(ID,CONCAT('chen',ID),CONCAT('haixiang',ID),Now(),Now(),Now(),1,ID);
SET ID = ID + 1;
SET Var = Var + 1;
END WHILE;
END;
错误
SQL 查询:
CREATE PROCEDURE BatchInsert( IN init INT, IN loop_time INT ) BEGIN DECLARE Var INT;
MySQL 返回:
#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 Var INT' at line 5 展开
BEGIN
DECLARE Var INT;
DECLARE ID INT;
SET Var = 0;
SET ID = init;
WHILE Var < loop_time DO
insert into employees(id,fname,lname,birth,hired,separated,job_code,store_id) values(ID,CONCAT('chen',ID),CONCAT('haixiang',ID),Now(),Now(),Now(),1,ID);
SET ID = ID + 1;
SET Var = Var + 1;
END WHILE;
END;
错误
SQL 查询:
CREATE PROCEDURE BatchInsert( IN init INT, IN loop_time INT ) BEGIN DECLARE Var INT;
MySQL 返回:
#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 Var INT' at line 5 展开
2个回答
展开全部
稍微给你改了下,,,可以了
CREATE PROCEDURE BatchInsert(IN init INT, IN loop_time INT)
BEGIN
DECLARE Var INT;
DECLARE ID INT;
SET Var = 0;
SET ID = init;
WHILE Var < loop_time DO
insert into employees(id,fname,lname,birth,hired,separated,job_code,store_id)
values(ID,CONCAT('chen',ID),CONCAT('haixiang',ID),Now(),Now(),Now(),1,ID);
SET ID = ID + 1;
SET Var = Var + 1;
END WHILE;
END;
你的语句没错误,但是估计是你行间有空格,导致语句错误,排了下版就可以了
追答
还是1064语法错误,你再看看你哪句里面有空格吧,,,你看我用我刚发的语句
[SQL] CREATE PROCEDURE BatchInsert(IN init INT, IN loop_time INT)
BEGIN
DECLARE Var INT;
DECLARE ID INT;
SET Var = 0;
SET ID = init;
WHILE Var < loop_time DO
insert into employees(id,fname,lname,birth,hired,separated,job_code,store_id)
values(ID,CONCAT('chen',ID),CONCAT('haixiang',ID),Now(),Now(),Now(),1,ID);
SET ID = ID + 1;
SET Var = Var + 1;
END WHILE;
END;
受影响的行: 0
时间: 0.031s
展开全部
在最上层添加 delimiter $$ 在END之后加$$试试
delimiter $$
CREATE PROCEDURE BatchInsert(IN init INT, IN loop_time INT)
BEGIN
DECLARE Var INT;
DECLARE ID INT;
SET Var = 0;
SET ID = init;
WHILE Var < loop_time DO
insert into employees(id,fname,lname,birth,hired,separated,job_code,store_id)
values(ID,CONCAT('chen',ID),CONCAT('haixiang',ID),Now(),Now(),Now(),1,ID);
SET ID = ID + 1;
SET Var = Var + 1;
END WHILE;
END $$
delimiter $$
CREATE PROCEDURE BatchInsert(IN init INT, IN loop_time INT)
BEGIN
DECLARE Var INT;
DECLARE ID INT;
SET Var = 0;
SET ID = init;
WHILE Var < loop_time DO
insert into employees(id,fname,lname,birth,hired,separated,job_code,store_id)
values(ID,CONCAT('chen',ID),CONCAT('haixiang',ID),Now(),Now(),Now(),1,ID);
SET ID = ID + 1;
SET Var = Var + 1;
END WHILE;
END $$
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询