MySQL 存储过程中使用 WHILE 循环语句
时间:2016-05-26 13:51 来源:linux.it.net.cn 作者:IT
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
-> 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();
(责任编辑:IT)
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 -> 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(); (责任编辑:IT) |