MySql function – how to create functions
By Peter
Custom function in MySQL comes handy if we have some sort of calculation what to make, in order to get a value what can be stored. This implies that we want to push some logic into the database which is not a to popular idea among engineers.
A function always gives one value as a result like ‘select pi(); gives us 3.141593’.
To create a function the type of the input value(s) need to be specified as well as the output, result.
A real-world example would be to make a function to calculate VAT for some product.
The unique function created can be used within an insert statement, like