Home >Database >Mysql Tutorial >MySQL存储过程中使用WHILE循环语句的方法_MySQL

MySQL存储过程中使用WHILE循环语句的方法_MySQL

WBOY
WBOYOriginal
2016-06-01 12:59:271342browse

本文实例讲述了MySQL存储过程中使用WHILE循环语句的方法。分享给大家供大家参考。具体如下:

mysql>
mysql> delimiter $$
mysql>
mysql> CREATE PROCEDURE myProc()
 -> BEGIN
 ->
 ->  DECLARE i int;
 ->  SET i=1;
 ->  loop1: WHILE i<=10 DO
 ->   IF MOD(i,2)<>0 THEN /*Even number - try again*/
 ->    SELECT CONCAT(i," is an odd number");
 ->   END IF;
 ->   SET i=i+1;
 ->  END WHILE loop1;
 -> END$$
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> delimiter ;
mysql> call myProc();

希望本文所述对大家的MySQL数据库程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn