mysql>mysql>mysql> delimiter $$mysql> CREATE FUNCTION myFunction(normal_price NUMERIC(8,2)) -> RETURNS NUMERIC(8,2) -> BEGIN -> -> DECLARE discount_price NUMERIC(8,2); -> -> IF (normal_price>500) THEN -> SET discount_price=normal_price*.8; -> ELSEIF (normal_price>100) THEN -> SET discount_price=normal_price*.9; -> ELSE -> SET discount_price=normal_price; -> END IF; -> RETURN(discount_price); -> END$$Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;mysql>mysql> select myFunction(123.123);+---------------------+| myFunction(123.123) |+---------------------+| 110.81 |+---------------------+1 row in set, 2 warnings (0.02 sec)mysql>mysql>mysql> drop function myFunction;Query OK, 0 rows affected (0.00 sec)mysql>mysql>
Name (required)
email (will not be published) (required)
Website