You can create user-defined functions in MySQL. These are used to extend the functionality of MySQL, and they work much the same as other built-in functions work. As you may recall, built-in functions are things such as SUM() or AVG().
Creating and using functions
Understanding the difference between a function and a stored procedure
A function differs from a stored procedure in many ways, as shown in the following table:
Function |
Stored procedure |
Returns only one mandatory value |
Can return zero, one, or multiple values |
Doesn't allow transactions |
Allow transactions |
Can be used in SELECT, WHERE, and HAVING clauses |
Can't be used in SELECT, WHERE, and HAVING clauses |
Only allows input parameters... |