首頁  >  文章  >  資料庫  >  MySQL 的 LEAVE 语句退出循环

MySQL 的 LEAVE 语句退出循环

WBOY
WBOY原創
2016-06-07 14:54:313452瀏覽

无详细内容 MySQL mysqlmysql delimiter $$mysqlmysql 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 j12 THEN - LEAV

MySQL
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();
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn