IF : IF statement « Procedure Function « SQL / MySQL






IF

 



mysql>
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION delivery_day_shipping (delivery_day INT(1)) RETURNS INT(2)
    -> BEGIN
    ->
    -> DECLARE shipping_cost INT(2) DEFAULT 0;
    ->
    -> IF delivery_day = 1 THEN
    ->         SET shipping_cost = 20;
    -> ELSEIF delivery_day = 2 THEN
    ->         SET shipping_cost = 15;
    -> ELSEIF delivery_day = 3 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>

        








Related examples in the same category

1.If statement with ELSEIF and ELSE
2.Using OR in an IF statement
3.Check version with if statement
4.IF statement in a LOOP statement