语法:

repeat
SQL
until 条件 end repeat;

 

就是相当于其他语言中的:

do{
# 
   
}while();

 

 

 

 

 

 

 

mysql> create procedure p1p()
    ->   begin
    ->     declare count int default 0;
    ->     repeat
    ->       select user();
    ->       set count = count + 1;
    ->     until count>3 end repeat;
    ->   end$
Query OK, 0 rows affected (0.00 sec)

mysql> call p1p()$
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.01 sec)

+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.01 sec)

+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

mysql>

 

相关文章:

  • 2021-12-23
  • 2021-07-10
  • 2021-12-25
  • 2021-09-29
  • 2021-12-23
  • 2021-12-23
  • 2021-12-25
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-12-23
  • 2021-12-23
  • 2021-11-12
  • 2021-12-23
相关资源
相似解决方案