Blog > detail

Just my tiny mind

MySql Stored Function

26-2-2012 Admin General 2 Comments

MySql Stored Function

Continuing my previous MySql Stored Prochedure, in this article I will explain about MySql 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 //


create function find_root (source double) returns double



declare root double;

set root = sqrt(source);

return root;


delimiter ;

Second, Call the function.

select find_root(36);

In this case, the MySql Stored Function will find the square root of any value inserted.

Thats all about my article. Hope this MySql Stored Function will be useful for you.

MySql Stored Function

word word

MySql Stored Function

MySql Stored Function

MySql Stored Function