MySQL 存储过if语句用法,MySQL IF语句允许您根据表达式的某个条件或值结果来执行一组SQL语句。
1,if 结构
IF expression THEN
statements;
END IF;
IF expression THEN
statements;
ELSE
else-statements;
END IF;
IF expression THEN
statements;
ELSEIF elseif-expression THEN
elseif-statements;
ELSE
else-statements;
END IF;
2,if实例
DELIMITER $$
CREATE PROCEDURE GetCustomerLevel(
in p_customerNumber int(11),
out p_customerLevel varchar(10))
BEGIN
DECLARE creditlim double;
SELECT creditlimit INTO creditlim
FROM customers
WHERE customerNumber = p_customerNumber;
IF creditlim > 50000 THEN
SET p_customerLevel = 'PLATINUM';
ELSEIF (creditlim <= 50000 AND creditlim >= 10000) THEN
SET p_customerLevel = 'GOLD';
ELSEIF creditlim < 10000 THEN
SET p_customerLevel = 'SILVER';
END IF;
END$$
if用在存储过程中,多多实际实践,增加动手能力
文章来自 www.dc3688.com
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。