Single statement function : Function « Procedure Function « SQL / MySQL






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

1.Creating Functions
2.A function that takes a parameter, performs an operation using an SQL function, and returns the result
3.Nested function call
4.Using buildin function in user-defined function
5.To remove a stored function, use the DROP command
6.Create a procedure for 'READS SQL DATA'
7.Math calculation in a function
8.Function to shorten a string
9.Calculate number of day