官方英文文档:
http://dev.mysql.com/doc/refman/5.0/en/flow-control-statements.html
************************** IF **************************
语法:
IF search_condition THEN statement_list
[ELSEIF search_condition THEN statement_list] ...
[ELSE statement_list]
END IF
实例:
DELIMITER$$
DROP PROCEDURE IF EXISTS pro_if$$
CREATE PROCEDURE pro_if(
i INT
)
BEGIN
IF i < 60 THEN
SELECT '需继续努力,争取过线!' AS result;
ELSEIF i < 85 THEN
SELECT '再努力点,争取达优!' AS result;
ELSE
SELECT '不错哦,恭喜,恭喜!' AS result;
END IF;
END$$
************************** CASE **************************
语法:
CASE case_value
WHEN when_value THEN statement_list
[WHEN when_value THEN statement_list] ...
[ELSE statement_list]
END CASE
Or:
CASE
WHEN search_condition THEN statement_list
[WHEN search_condition THEN statement_list] ...
[ELSE statement_list]
END CASE
实例:
DELIMITER$$
DROP PROCEDURE IF EXISTS pro_case$$
CREATE PROCEDURE pro_case(
i INT
)
BEGIN
CASE i
WHEN 1 THEN SELECT 'you male!' AS result;
WHEN 0 THEN SELECT 'you female!' AS result;
ELSE
SELECT 'third sex!' AS result;
END CASE;
END$$
分享到:
2013-03-25 18:07
浏览 954
分类:数据库
评论