MySQL 的 LEAVE 语句退出循环

太阳集团所有网址16877,sql代码

mysql>
mysql> delimiter $$
mysql>
mysql> CREATE PROCEDURE myProc()
    -> BEGIN
    ->     DECLARE i,j INT DEFAULT 1;
    ->     outer_loop: LOOP
    ->          SET j=1;
    ->          inner_loop: LOOP
    ->               SELECT CONCAT(i," times ", j," is ",i*j);
    ->               SET j=j 1;
    ->               IF j>12 THEN
    ->                    LEAVE inner_loop;
    ->               END IF;
    ->          END LOOP inner_loop;
    ->          SET i=i 1;
    ->          IF i>12 THEN
    ->               LEAVE outer_loop;
    ->          END IF;
    ->     END LOOP outer_loop;
    ->
    ->
    ->
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql> call myProc();

本文由太阳集团所有网址16877发布于太阳集团城网址送彩金,转载请注明出处:MySQL 的 LEAVE 语句退出循环

您可能还会对下面的文章感兴趣: