User-defined function

This is an old revision of this page, as edited by Mikeblas (talk | contribs) at 21:50, 17 June 2006 (pass at rewrite). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A User Defined Function, or UDF, is a function provided by the user of a program or environment, in a context where the usual assumption is that functions are built into the program or environment.

BASIC language

In some old implementations of the BASIC programming language, user defined functions are defined using the "DEF FN" syntax. More modern dialects of BASIC are influenced by the structured programming paradigm, where most or all code is written as user defined functions or procedures, and the concept becomes practically redundant.


Databases

In SQL Databases, a user-defined function provides a mechanism for extending to the database server by adding a function that can evaluated in SQL queries. User defined functions in SQL are declared using the CREATE FUNCTION keywords. For example, a function that converts Celcius to Fharenheit might be declared like this:

CREATE FUNCTION CtoF(@celcius FLOAT) RETURNS FLOAT AS BEGIN return (@celcius * 1.8) + 32 END

Once created, the user-defined function may be invoked where most other intrinsic functions are available. This includes SELECT statements, where the function can be used against data stored in the 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).