码迷,mamicode.com
首页 > 数据库 > 详细

Mysql储存过程8:repeat循环

时间:2017-07-04 09:55:29      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:style   mysq   过程   ted   end   cal   blog   循环   color   

语法:

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>

 

Mysql储存过程8:repeat循环

标签:style   mysq   过程   ted   end   cal   blog   循环   color   

原文地址:http://www.cnblogs.com/perl6/p/7114773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!