mysql 循环存储过程

create procedure cunchu1(a int)
begin
	DECLARE count int default 0; -- 定义变量
	DECLARE i int default 1;
loop_name:loop -- 循环开始 loop_name 为循环名称 loop循环
if i>a then -- 当 i 大于传进来的 值a 时 退出循环
LEAVE loop_name; -- 判断条件成立则结束循环 好比java中的 boeak
end if;
	UPDATE way_bridge_info_ext set uuid=REPLACE(UUID(),'-','') where uuid=i and CREATE_TIME='2018-4-26 15:49:40';	-- 循环执行操作
set count=i+1;	-- 赋值 set 
set i=i+1;
end loop; -- 循环结束
SELECT count;	-- 查询
end -- 结束

call cunchu1(29);	-- 执行存储过程

-- 删除存储过程
drop procedure if exists cunchu1;

  

create procedure sum1(a int)
begin
declare sum int default 0; -- default 是指定该变量的默认值
declare i int default 1;
while i<=a DO -- 循环开始
set sum=sum+i;
set i=i+1;
end while; -- 循环结束
select sum; -- 输出结果
end
-- 执行存储过程
call sum1(100);
-- 删除存储过程
drop procedure if exists sum1

原文地址:https://www.cnblogs.com/wcnwcn/p/8866170.html