MySql Stored Function

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.

select find_root(36);

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.

 

http://septiadi.com/2011/04/04/mysql-stored-function/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: