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
原文地址:http://blog.51cto.com/13959155/2292206
时间: 2024-10-09 20:37:43