mysql 存储过程 显示控制_mysql存储过程之控制语句篇
loop的使用 要結合leave 和 iterate
看到名字 都已經大概 猜測到了 意思
leave 就是離開退出循環 而 iterate就是 繼續迭代
CREATE PROCEDURE ABC()
BEGIN
DECLARE a INT Default 0 ;
simple_loop: LOOP
SET a=a+1;
select a;
IF a=5 THEN
LEAVE simple_loop;
END IF;
END LOOP simple_loop;
END
create procedure pro
begin
declare a int default 1;
label1: loop
if a<6 then
select a;
set a=a+1;
iterate label1;
end if;
leave label1;
end loop label1;
end
3.REPEAT[begin_label:] REPEAT
statement_list
UNTIL search_condition
END REPEAT [end_label]
REPEAT語句內的語句或語句群被重復,直至search_condition為真。
create procedure pro
begin
declare a int default 3;
repeat
select a;
set a=a+1;
untile a>5 end repeat;
end
4.while
[label:] WHILE 條件 DO--循環處理END WHILE [label];
create procedure pro
begin
declare a int default 4;
while a<10 do
select a;
set a=a+1;
end while;
end
下面是一個摘抄的例子,主要看while如何使用
WHILE (id is not null ) DO
if(month='01'||month='02'||month='03') THEN set season='1';
end if;
if(month='04'||month='05'||month='06') THEN set season='2';
end if;
if(month='07'||month='08'||month='09') THEN set season='3';
end if;
if(month='10'||month='11'||month='12') THEN set season='4';
end if;
update t_industry_finance_instance set season_=season where ID_=id;
FETCH cur1 INTO id,month;
END WHILE;
總結
以上是生活随笔為你收集整理的mysql 存储过程 显示控制_mysql存储过程之控制语句篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dapper mysql 批量_MySQ
- 下一篇: aws java mysql_AWS S