Single statement function
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION calc_tax (cost DECIMAL(10,2)) RETURNS DECIMAL(10,2)
-> RETURN cost * .05
-> //
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> DELIMITER ;
mysql>
mysql> select calc_tax(123.123);
+-------------------+
| calc_tax(123.123) |
+-------------------+
| 6.16 |
+-------------------+
1 row in set, 2 warnings (0.00 sec)
mysql>
mysql> drop function calc_tax;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category