How to add a new function to MySQL

Source: Internet
Author: User

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,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.