MYSQL儲存過程-練習3 repeat迴圈

_飞翔的荷兰人發表於2024-05-14

repeat迴圈

 1 DELIMITER $$
 2 
 3 CREATE PROCEDURE `sp_repeat`()
 4 BEGIN
 5   DECLARE i INT;
 6   SET i=1;
 7   REPEAT
 8     SELECT i;
 9     SET i=i+1;
10     UNTIL i>=5
11   END REPEAT;
12 END$$
13 
14 DELIMITER ;

執行儲存過程

 1 mysql> call sp_repeat();
 2 +------+
 3 | i    |
 4 +------+
 5 |    1 |
 6 +------+
 7 1 row in set (0.00 sec)
 8 
 9 +------+
10 | i    |
11 +------+
12 |    2 |
13 +------+
14 1 row in set (0.01 sec)
15 
16 +------+
17 | i    |
18 +------+
19 |    3 |
20 +------+
21 1 row in set (0.02 sec)
22 
23 +------+
24 | i    |
25 +------+
26 |    4 |
27 +------+
28 1 row in set (0.02 sec)
29 
30 Query OK, 0 rows affected (0.03 sec)

相關文章