最近遇到這樣的問(wèn)題,在MySQL的存儲(chǔ)過(guò)程中,游標(biāo)操作時(shí),需要執(zhí)行一個(gè)conitnue的操作.眾所周知,MySQL中的游標(biāo)循環(huán)操作常用的有三種,LOOP,REPEAT,WHILE.三種循環(huán),方式大同小異.以前從沒(méi)用過(guò),所以記下來(lái),方便以后查閱.
1.REPEAT
代碼如下:
REPEAT
Statements;
UNTIL expression
END REPEAT
demo
DECLARE num INT;
DECLARE my_string VARCHAR(255);
REPEAT
SET my_string =CONCAT(my_string,num,',');
SET num = num +1;
UNTIL num <5
END REPEAT;
2.WHILE
代碼如下:
WHILE expression DO
Statements;
END WHILE
demo
DECLARE num INT;
DECLARE my_string VARCHAR(255);
SET num =1;
SET str ='';
WHILE num < span>10DO
SET my_string =CONCAT(my_string,num,',');
SET num = num +1;
END WHILE;
3.LOOP(這里面有非常重要的ITERATE,LEAVE)
代碼如下:
DECLARE num INT;
DECLARE str VARCHAR(255);
SET num =1;
SET my_string ='';
loop_label: LOOP
IF num <10THEN
LEAVE loop_label;
ENDIF;
SET num = num +1;
IF(num mod3)THEN
ITERATE loop_label;
ELSE
SET my_string =CONCAT(my_string,num,',');
ENDIF;
END LOOP;
PS:可以這樣理解ITERATE就是我們程序中常用的contiune,而ITERATE就是break.當(dāng)然在MySQL存儲(chǔ)過(guò)程,需要循環(huán)結(jié)構(gòu)有個(gè)名稱,其他都是一樣的.
更多信息請(qǐng)查看IT技術(shù)專欄