1. 程式人生 > >MySQL 存儲過if語句用法

MySQL 存儲過if語句用法

elseif custom ble latin roc where varchar 文章 用法

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

MySQL 存儲過if語句用法