数据库
首页 > 数据库> > mysql (:kabel_name:loop...end loop"; "repeat....end repeat";"while ... do .... e

mysql (:kabel_name:loop...end loop"; "repeat....end repeat";"while ... do .... e

作者:互联网

drop PROCEDURE if exists test1;
create procedure test1()
begin
    declare i int;
    set i=1;
while i<=30 do
        update blog.car1_myarticle 
        set blog.car1_myarticle.brief_content=i
        where car1_myarticle.id=i;
        set i=i+1;
end while;
end;
----------------------------------------
drop PROCEDURE if exists test1;
create procedure test1()
begin
    declare i int;
    set i=1;
exit_a:loop  -- 定义一个标签为 "exit_a"
        update blog.car1_myarticle 
        set blog.car1_myarticle.brief_content=i
        where car1_myarticle.id=i;
        set i=i+1;
    if i>30 THEN
        LEAVE exit_a;  -- 离开指定的标签 "exit_a"
    end if;
end loop;
end;
----------------------------------------
drop procedure if EXISTS test1;
create procedure test3()
begin
    declare i,n int;
    set i=1;
    set n=30;
REPEAT
            update blog.car1_myarticle 
            set blog.car1_myarticle.brief_content=i
            where car1_myarticle.id=i;
set i=i+1;
until i>n
end REPEAT;
end;

 

标签:test1,...,set,end,car1,while,repeat,myarticle
来源: https://www.cnblogs.com/vmsysjack/p/13055978.html