【MySQL】MySQL 执行创建存储过程报错的解决方法

源码

创建使用while循环插入数据的存储过程

设置mysql分隔符为//
delimiter // 
drop procedure if exists while1 ;
create procedure while1()
begin
declare i int default 0;
set i = 0 ;
while i < 10 do
insert into test_table(tname) values('TestName1');
set i = i + 1 ;
end while;
select * from test_table;
end 
// 
call while1();
delimiter ;

执行

执行后可以看到数据库中已经有了while1存储过程,证明命令已经成功执行

但是报错:Error Code: 2014 Commands out of sync; you can't run this command now


解决方法

将上述语句中的

drop procedure if exists while1 ;

改为

drop procedure id exists while1 //

问题解决

posted @ 2022-10-13 00:33  HookDing  阅读(369)  评论(0编辑  收藏  举报