首页 » 技术分享 » 存储过程LEAVE的用法

存储过程LEAVE的用法

 

DELIMITER $$

USE `test`$$

DROP PROCEDURE IF EXISTS `liangzi`$$

CREATE DEFINER=`admin`@`%` PROCEDURE `liangzi`(IN i INT)

    xiaoliangzi:BEGIN
    IF i=1 THEN
       SELECT 1;
       LEAVE xiaoliangzi;
       SELECT 'BBS';
    ELSEIF i=2 THEN
       SELECT 2;
       LEAVE xiaoliangzi;
       SELECT 'BBS';
    ELSE
       SELECT 3;
       SELECT 'BBS';
    END IF;  
       SELECT 'BLOG.51CTO.COM';
    END$$

DELIMITER ;

-- ------------------------------------------

mysql> call liangzi(2);


+---+


| 2 |


+---+


| 2 |


+---+


1 row in set (0.00 sec)

-- ------------------------------------------

mysql> call liangzi(3);


+---+


| 3 |


+---+


| 3 |


+---+


1 row in set (0.00 sec)




+-----+


| BBS |


+-----+


| BBS |


+-----+


1 row in set (0.00 sec)




+----------------+


| BLOG.51CTO.COM |


+----------------+


| BLOG.51CTO.COM |


+----------------+


1 row in set (0.00 sec)




Query OK, 0 rows affected (0.00 sec)

-- ------------------------------------------

mysql> call liangzi(4);


+---+


| 3 |


+---+


| 3 |


+---+


1 row in set (0.00 sec)




+-----+


| BBS |


+-----+


| BBS |


+-----+


1 row in set (0.00 sec)




+----------------+


| BLOG.51CTO.COM |


+----------------+


| BLOG.51CTO.COM |


+----------------+


1 row in set (0.00 sec)




Query OK, 0 rows affected (0.00 sec)

本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/806740

转载自原文链接, 如需删除请联系管理员。

原文链接:存储过程LEAVE的用法,转载请注明来源!

0