循环结构 while create procedure name() begin while 条件 do SQL语句 end while; end$ create procedure aa6() begin declare number int default 0; while number < 5 do select number; set number = number + 1; end while; end$ mysql> create procedure aa6() -> begin -> declare number int default 0; -> while number < 5 do -> select number; -> set number = number + 1; -> end while; -> end$Query OK, 0 rows affected (0.00 sec) mysql> call aa6$+--------+| number |+--------+| 0 |+--------+1 row in set (0.00 sec) +--------+| number |+--------+| 1 |+--------+1 row in set (0.01 sec) +--------+| number |+--------+| 2 |+--------+1 row in set (0.01 sec) +--------+| number |+--------+| 3 |+--------+1 row in set (0.01 sec) +--------+| number |+--------+| 4 |+--------+1 row in set (0.02 sec) Query OK, 0 rows affected (0.02 sec)
时间: 2024-10-04 16:09:32