Home > Database > Mysql Tutorial > body text

MySQL 的 LEAVE 语句退出循环

WBOY
Release: 2016-06-07 14:54:31
Original
3407 people have browsed it

无详细内容 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();
Copy after login
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!