Functions are very useful to perform the same task with different parameters. Similar to programming languages you can create your own custom function to perform a task and return a response in MySQL.
After function creation, it is called similar to inbuilt functions.
In this tutorial, I show how you can create a function in MySQL and use it.