There are two ways to add new functions for MySQL:
You can add functions through your own Medical function interface (UDF). The custom function is compiled into the destination file and then dynamically added to the server and removed from the server with the CREATE function and the drop FUNCTION declaration.
You can add functions as MySQL intrinsic (built-in) functions. Intrinsic functions are compiled into the MYSQLD server and become permanently available.
Each of these approaches has its advantages and disadvantages:
If you write a custom function, you install the target file in addition to the server itself. If you compile your functions into a server, you don't need to do that.
You can add a UDF to a binary version of the MySQL distribution. The intrinsic function requires you to revise the source distribution version.
If you upgrade your MySQL distribution, you can continue using the previously installed UDF unless you upgrade to a new version of the UDF interface that changed. For intrinsic functions, you must repeat the correction every time you upgrade.
Whichever method you use to add new functions, they can be invoked by the SQL declaration, just like the intrinsic functions of ABS () or SOUNDEX ().
Another method to add a function to create a stored function. These functions are written in an SQL declaration, rather than as a compilation of the target code. The syntax for writing stored functions is described in chapter 20th: stored programs and functions.
The following subsections describe the features of the UDF interface, give instructions for writing the UDF, and discuss the security precautions that MySQL has taken to prevent the UDF from being misused.
Give examples of the source code to illustrate how to write UDF, you can look at the MySQL source distribution of the sql/udf_example.cc file provided.
Note : For more wonderful tutorials, please pay attention to the triple graphics tutorial channel,