Home  >  Article  >  Database  >  MySQL 存储过程中使用 WHILE 循环语句_MySQL

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

PHP中文网
PHP中文网Original
2016-05-27 14:29:421202browse

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

 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 存储过程中使用 WHILE 循环语句_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


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