– 更新site_reosurce_moniotr的时间,执行一次就加一天时间
delimiter // ;
drop procedure if exists test;
create procedure test()
begin
declare i int;
set i = 1;
while i <= 410 do
UPDATE `flexedge-mec`.`site_resource_monitor` m
SET m.`report_time` = DATE_ADD((select d.time FROM (SELECT s.report_time as time FROM site_resource_monitor s WHERE s.id=i) d),INTERVAL 1 DAY) WHERE m.id=i;
set i = i + 1;
end while;
end
//
call test();
– 更新vm_usage_moniotr的时间,执行一次就加一天时间
delimiter // ;
drop procedure if exists test;
create procedure test()
begin
declare i int;
set i = 2034;
while i <= 3093 do
UPDATE `flexedge-mec`.`vm_usage_monitor` m
SET m.`report_time` = DATE_ADD((select d.time FROM (SELECT s.report_time as time FROM vm_usage_monitor s WHERE s.id=i) d),INTERVAL 1 DAY) WHERE m.id=i;
set i = i + 1;
end while;
end
//
call test();
– while循环模板
delimiter // #定义标识符为双斜杠
drop procedure if exists test; #如果存在test存储过程则删除
create procedure test() #创建无参存储过程,名称为test
begin
declare i int; #申明变量
set i = 0; #变量赋值
while i < 10 do #结束循环的条件: 当i大于10时跳出while循环
insert into test values (i); #往test表添加数据
set i = i + 1; #循环一次,i加一
end while; #结束while循环
select * from test; #查看test表数据
end
// #结束定义语句
call test(); #调用存储过程
– repeat循环模板
delimiter // #定义标识符为双斜杠
drop procedure if exists test; #如果存在test存储过程则删除
create procedure test() #创建无参存储过程,名称为test
begin
declare i int; #申明变量
set i = 0; #变量赋值
repeat
insert into test values (i); #往test表添加数据
set i = i + 1; #循环一次,i加一
until i > 10 end repeat; #结束循环的条件: 当i大于10时跳出repeat循环
select * from test; #查看test表数据
end
// #结束定义语句
call test(); #调用存储过程
– loop循环模板
delimiter // #定义标识符为双斜杠
drop procedure if exists test; #如果存在test存储过程则删除
create procedure test() #创建无参存储过程,名称为test
begin
declare i int; #申明变量
set i = 0; #变量赋值
lp : loop #lp为循环体名,可随意 loop为关键字
insert into test values (i); #往test表添加数据
set i = i + 1; #循环一次,i加一
if i > 10 then #结束循环的条件: 当i大于10时跳出loop循环
leave lp;
end if;
end loop;
select * from test; #查看test表数据
end
// #结束定义语句
call test(); #调用存储过程