mysql的for循环_MySQL中的For循环示例
三國紛爭
MySQL中的while循環語法示例:delimiter //CREATE procedure yourdatabase.while_example()wholeblock:BEGIN? declare str VARCHAR(255) default '';? declare x INT default 0;? SET x = 1;? WHILE x <= 5 DO? ? SET str = CONCAT(str,x,',');? ? SET x = x + 1;? END WHILE;? select str;END//哪些打印:mysql> call while_example();+------------+| str? ? ? ? |+------------+| 1,2,3,4,5, |+------------+MySQL中的REPEAT循環語法示例:delimiter //CREATE procedure yourdb.repeat_loop_example()wholeblock:BEGIN? DECLARE x INT;? DECLARE str VARCHAR(255);? SET x = 5;? SET str = '';? REPEAT? ? SET str = CONCAT(str,x,',');? ? SET x = x - 1;? ? UNTIL x <= 0? END REPEAT;? SELECT str;END//哪些打印:mysql> call repeat_loop_example();+------------+| str? ? ? ? |+------------+| 5,4,3,2,1, |+------------+MySQL中的FOR循環語法示例:delimiter //CREATE procedure yourdatabase.for_loop_example()wholeblock:BEGIN? DECLARE x INT;? DECLARE str VARCHAR(255);? SET x = -5;? SET str = '';? loop_label: LOOP? ? IF x > 0 THEN? ? ? LEAVE loop_label;? ? END IF;? ? SET str = CONCAT(str,x,',');? ? SET x = x + 1;? ? ITERATE loop_label;? END LOOP;? SELECT str;END//哪些打印:mysql> call for_loop_example();+-------------------+| str? ? ? ? ? ? ? ?|+-------------------+| -5,-4,-3,-2,-1,0, |+-------------------+1 row in set (0.00 sec)進行本教程:http : //www.mysqltutorial.org/stored-procedures-loop.aspx如果我發現您將這種MySQL for循環構造推入生產,那么我將用泡沫導彈發射器向您射擊。您可以使用管扳手敲打釘子,但是這樣做會使您看起來很傻。
總結
以上是生活随笔為你收集整理的mysql的for循环_MySQL中的For循环示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 14.安全
- 下一篇: mysql noinstall_免安装版