MySql Stored Function
Continuing my previous MySql Stored Prochedure, in this article I will explain aboutMySql Stored Function.
Different with MySql Stored Prochedure, MySql Stored Function, has to return a value. MySql Stored Function is a declaration function saved in MySql that will run some method/prochedure then return value to the user. To be remembered, MySql Stored Function only return a single value. Therefore it is imposible to return table.
The benefit and the drawback of MySql Stored Function is similar with MySql Stored Prochedure.
What is the benefit of MySql Stored Function?
- Run faster than SQL command send from application
- Increase the performance of the application
- Reduce requseted command. How? Instead sending multiple command. The application may send only one trigger, and MySql will do the rest
- MySql Stored Function can be accessed by many type of application
- More secure. How? MySql Stored Function, only reveal the requested result to user.
What is the drawback of MySql Stored Function?
- Database server will have more load to do. In this case, it make high usage of memory and processor.
- You cant debug MySql Stored Function.
Lets build MySql Stored Function
First, make the function.
delimiter // DROP FUNCTION IF EXISTS find_root// create function find_root (source double) returns double deterministic begin declare root double; set root = sqrt(source); return root; end// delimiter ;
Second, Call the function.
In this case, the MySql Stored Function will find the square root of any value inserted.
Thats all about MySql Stored Function article. Hope this MySql Stored Function will be useful for you.