In someSQL databasesDatabases, a UDFuser-defined orfunction [[storedprovides procedure]]a ismechanism anfor [[extension (computing)|extensionextending]] to the [[database server]] (likeby [[MySQL]])adding a function that can be compiled for useevaluated in an [[SQL]][[database query language|query]]queries. ForUser example,defined sometimesfunctions itin maySQL beare necessarydeclared tousing obtainthe a<code>CREATE [[random]]FUNCTION</code> numberkeywords. forFor useexample, as a [[primary key]] (a function that MySQLconverts doesCelcius notto internallyFharenheit support). In this case, a new external function couldmight be writtendeclared and compiled to accomplishlike this task. :
<code>
One sample of such a query could be: <code>SELECT GETRANDOMKEY();</code>.
CREATE FUNCTION CtoF(@celcius FLOAT)
RETURNS FLOAT
AS
BEGIN
return (@celcius * 1.8) + 32
END
</code>
EssentiallyOnce created, thisthe externaluser-defined function becomesmay partbe ofinvoked thewhere servermost itself.other intrinsic functions are available. This canincludes alsoSELECT knownstatements, aswhere athe [[userfunction exit]]can (e.g.be used against data stored in the [[Adabas]] database)
Some database management systems allow the creation of user defined functions in languages other than SQL. Mirosoft SQL Server, for example, allows the user to use .NET languages for this purpose.
This can also known as a [[user exit]] (e.g. in the [[Adabas]] database).
==External links==
* [http://msdn.microsoft.com/library/en-us/tsqlref/ts_create_7r1l.asp Microsoft SQL Server reference for CREATE FUNCTION]
* [http://dev.mysql.com/doc/refman/5.0/en/adding-functions.html MySQL manual section on UDFs]