MySQL 5.1 リファレンスマニュアル :: 25 Extending MySQL :: 25.3 Adding New Functions to MySQL
« 25.2.5.3 Creating a Plugin Library

25.3.1 Features of the User-Defined Function Interface »
Section Navigation      [Toggle]
  • 25 Extending MySQL
  • 25.1 MySQL Internals
  • 25.2 The MySQL Plugin Interface
  • 25.3 Adding New Functions to MySQL
    • 25.3.1 Features of the User-Defined Function Interface
    • 25.3.2 CREATE FUNCTION Syntax
    • 25.3.3 DROP FUNCTION Syntax
    • 25.3.4 Adding a New User-Defined Function
    • 25.3.5 Adding a New Native Function
  • 25.4 Adding New Procedures to MySQL

25.3. Adding New Functions to MySQL

[+/-]

25.3.1. Features of the User-Defined Function Interface
25.3.2. CREATE FUNCTION Syntax
25.3.3. DROP FUNCTION Syntax
25.3.4. Adding a New User-Defined Function
25.3.5. Adding a New Native Function

There are two ways to add new functions to MySQL:

  • You can add functions through the user-defined function (UDF) interface. User-defined functions are compiled as object files and then added to and removed from the server dynamically using the CREATE FUNCTION and DROP FUNCTION statements. See 項25.3.2. 「CREATE FUNCTION Syntax」.

  • You can add functions as native (built-in) MySQL functions. Native functions are compiled into the mysqld server and become available on a permanent basis.

Each method has advantages and disadvantages:

  • If you write user-defined functions, you must install object files in addition to the server itself. If you compile your function into the server, you don't need to do that.

  • Native functions require you to modify a source distribution. UDFs do not. You can add UDFs to a binary MySQL distribution. No access to MySQL source is necessary.

  • If you upgrade your MySQL distribution, you can continue to use your previously installed UDFs, unless you upgrade to a newer version for which the UDF interface changes. For native functions, you must repeat your modifications each time you upgrade.

Whichever method you use to add new functions, they can be invoked in SQL statements just like native functions such as ABS() or SOUNDEX().

Another way to add functions is by creating stored functions. These are written using SQL statements rather than by compiling object code. The syntax for writing stored functions is described in 章 17. ストアドプロシージャとファンクション.

See 項8.2.4. 「関数名の構文解析と名前解決」, for the rules describing how the server interprets references to different kinds of functions.

The following sections describe features of the UDF interface, provide instructions for writing UDFs, discuss security precautions that MySQL takes to prevent UDF misuse, and describe how to add native mySQL functions.

For example source code that illustrates how to write UDFs, take a look at the sql/udf_example.c file that is provided in MySQL source distributions.

Copyright © 1997, 2010, Oracle and/or its affiliates. All rights reserved. Legal Notices
Top / Previous / Next / Up / Table of Contents
© 2010, Oracle Corporation and/or its affiliates