IF : IF statement : Procedure Function MySQL TUTORIALS


MySQL TUTORIALS » Procedure Function » IF statement »

 

IF


IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list...
    [ELSE statement_list]
END IF

If statement checks a condition, running the statements in the block if the condition is true.

You can add ELSEIF statements to continue attempting to match conditions.

If desired, include a final ELSE statement.

mysql>
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION delivery_day_shipping (delivery_day INT(1)) RETURNS INT(2)
    -> BEGIN
    ->
    -> DECLARE shipping_cost INT(2DEFAULT 0;
    ->
    -> IF delivery_day = THEN
    ->         SET shipping_cost = 20;
    -> ELSEIF delivery_day = THEN
    ->         SET shipping_cost = 15;
    -> ELSEIF delivery_day = THEN
    ->         SET shipping_cost = 10;
    -> ELSE
    ->         SET shipping_cost = 5;
    -> END IF;
    ->
    -> RETURN shipping_cost;
    ->
    -> END
    -> //
ERROR 1304 (42000): FUNCTION delivery_day_shipping already exists
mysql> DELIMITER ;
mysql>
mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Procedure Function
» IF statement