Single statement function : Function « Procedure Function « MySQL Tutorial






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)








11.3.Function
11.3.1.Creating Functions
11.3.2.A function that takes a parameter, performs an operation using an SQL function, and returns the result
11.3.3.Single statement function
11.3.4.Nested function call
11.3.5.Using buildin function in user-defined function
11.3.6.Changing and Removing Functions
11.3.7.To remove a stored function, use the DROP command
11.3.8.Create a procedure for 'READS SQL DATA'
11.3.9.ALTER PROCEDURE and ALTER FUNCTION Syntax
11.3.10.DROP PROCEDURE and DROP FUNCTION Syntax
11.3.11.Function Permissions