<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.aletopedia.org/index.php?action=history&amp;feed=atom&amp;title=User-defined_function</id>
	<title>User-defined function - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.aletopedia.org/index.php?action=history&amp;feed=atom&amp;title=User-defined_function"/>
	<link rel="alternate" type="text/html" href="https://www.aletopedia.org/index.php?title=User-defined_function&amp;action=history"/>
	<updated>2026-12-04T21:14:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.2</generator>
	<entry>
		<id>https://www.aletopedia.org/index.php?title=User-defined_function&amp;diff=933167&amp;oldid=prev</id>
		<title>imported&gt;BorgHunter: Fix pandas link</title>
		<link rel="alternate" type="text/html" href="https://www.aletopedia.org/index.php?title=User-defined_function&amp;diff=933167&amp;oldid=prev"/>
		<updated>2026-10-31T20:07:34Z</updated>

		<summary type="html">&lt;p&gt;Fix pandas link&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Function provided by the user of a program or environment}}&lt;br /&gt;
{{More footnotes needed|date=July 2026}}&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;user-defined function&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;UDF&amp;#039;&amp;#039;&amp;#039;) is a [[function (programming)|function]] provided by the user of a [[Computer program|program]] or environment,{{Clarify|reason=What kind of environment? An integrated development environment? Perhaps the intended meaning is closer to &amp;quot;software framework&amp;quot; or &amp;quot;library&amp;quot;.|date=July 2026}} in a context where the usual assumption is that functions are built into the program or environment.&amp;lt;ref&amp;gt;{{cite web |title=User-Defined Functions (UDFs) |url=https://pandas.pydata.org/pandas-docs/stable/user_guide/user_defined_functions.html |website=[[pandas (software)|pandas]] documentation |access-date=31 July 2026 |archive-url=https://web.archive.org/web/20260720181905/https://pandas.pydata.org/pandas-docs/stable/user_guide/user_defined_functions.html |archive-date=2026-07-20 |language=en |date=July 22, 2026 |version=v3.0.5 |url-status=live |quote=In pandas, User-Defined Functions (UDFs) provide a way to extend the library’s functionality by allowing users to apply custom computations to their data. While pandas comes with a set of built-in functions for data manipulation, UDFs offer flexibility when built-in methods are not sufficient.}}&amp;lt;/ref&amp;gt; UDFs are usually written for the requirement of its creator.&lt;br /&gt;
&lt;br /&gt;
==BASIC language==&lt;br /&gt;
{{Unreferenced section|date=July 2026}}&lt;br /&gt;
In some old implementations of the [[BASIC]] [[programming language]], user-defined functions are defined using the &amp;quot;DEF&amp;amp;nbsp;FN&amp;quot; syntax.  More modern dialects of BASIC are influenced by the [[structured programming]] paradigm, where most or all of the code is written as user-defined functions or procedures, and the concept becomes practically redundant.&lt;br /&gt;
&lt;br /&gt;
==COBOL language==&lt;br /&gt;
{{Unreferenced section|date=July 2026}}&lt;br /&gt;
In the [[COBOL]] programming language, a user-defined function is an entity that is defined by the user by specifying a FUNCTION-ID paragraph. A user-defined function must return a value by specifying the RETURNING phrase of the procedure division header and they are invoked using the function-identifier syntax.  See the ISO/IEC 1989:2014 Programming Language COBOL standard for details. &lt;br /&gt;
&lt;br /&gt;
As of May 2022, the IBM Enterprise COBOL for [[z/OS]] 6.4 ([[IBM COBOL]]) [[compiler]] contains support for user-defined functions.&lt;br /&gt;
&lt;br /&gt;
==Databases==&lt;br /&gt;
In [[relational database management system]]s, a user-defined function provides a mechanism for extending the functionality of the [[database server]] by adding a function, that can be evaluated in standard [[query language]] (usually [[SQL]]) statements. The SQL standard ([[ISO/IEC 9075]]) distinguishes between [[Scalar (computing)|scalar]] and table functions.&amp;lt;ref&amp;gt;{{Cite ISO standard|csnumber=76583|title=ISO/IEC 9075 &amp;amp;ndash; Information technology - Database languages - SQL|publisher=[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]] |url-access=registration}}&amp;lt;/ref&amp;gt;{{Full citation needed|date=July 2026|reason=Specifically, which part discusses user-defined functions? This link goes to part 1, which is the only one free-to-read. Page number and year would also help.}} A scalar function returns only a single value (or [[null (SQL)|NULL]]), whereas a table function returns a (relational) table comprising zero or more rows, each row with one or more columns.&lt;br /&gt;
&lt;br /&gt;
User-defined functions in SQL are declared using the &amp;lt;code&amp;gt;CREATE FUNCTION&amp;lt;/code&amp;gt; statement. For example, a user-defined function that converts [[Celsius]] to [[Fahrenheit]] might be declared like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
CREATE FUNCTION dbo.CtoF(Celsius FLOAT)&lt;br /&gt;
  RETURNS FLOAT&lt;br /&gt;
  RETURN (Celsius * 1.8) + 32&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once created, a user-defined function may be used in [[expression (programming)|expressions]] in SQL statements. For example, it can be invoked where most other intrinsic functions are allowed. This also includes [[Select (SQL)|SELECT statements]], where the function can be used against data stored in tables in the database. Conceptually, the function is evaluated once per row in such usage. For example, assume a table named {{Code|Elements}}, with a row for each known chemical element. The table has a column named BoilingPoint for the boiling point of that element, in Celsius. The query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
SELECT Name, CtoF(BoilingPoint)&lt;br /&gt;
  FROM Elements&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
would retrieve the name and the boiling point from each row. It invokes the &amp;lt;code&amp;gt;CtoF&amp;lt;/code&amp;gt; user-defined function as declared above in order to convert the value in the column to a value in Fahrenheit.&lt;br /&gt;
&lt;br /&gt;
Each user-defined function carries certain properties or characteristics. The SQL standard defines the following properties:&lt;br /&gt;
*Language - defines the programming language in which the user-defined function is implemented; examples include SQL, C, C# and Java.&lt;br /&gt;
*Parameter style - defines the conventions that are used to pass the function parameters and results between the implementation of the function and the database system (only applicable if language is not SQL).&lt;br /&gt;
*Specific name - a name for the function that is unique within the database. Note that the function name does not have to be unique, considering [[overloaded function]]s. Some SQL implementations require that function names are unique within a database, and overloaded functions are not allowed.&lt;br /&gt;
* Determinism - specifies whether the function is deterministic or not. The determinism characteristic has an influence on the [[query optimizer]] when compiling a SQL statement. &lt;br /&gt;
*SQL-data access - tells the database management system whether the function contains no SQL statements (NO SQL), contains SQL statements but does not access any tables or [[view (SQL)|view]]s (CONTAINS SQL), reads data from tables or views (READS SQL DATA), or actually modifies data in the database (MODIFIES SQL DATA).&lt;br /&gt;
&lt;br /&gt;
User-defined functions should not be confused with [[stored procedure]]s. Stored procedures allow the user to group a set of SQL commands. A procedure can accept parameters and execute its SQL statements depending on those parameters. A procedure is not an expression and, thus, cannot be used like user-defined functions.&lt;br /&gt;
&lt;br /&gt;
Some database management systems allow the creation of user defined functions in languages other than SQL. [[Microsoft SQL Server]], for example, allows the user to use [[List of CLI languages|.NET languages]] including C# for this purpose. DB2 and Oracle support user-defined functions written in C or Java programming languages.&lt;br /&gt;
&lt;br /&gt;
===SQL Server 2000===&lt;br /&gt;
There are three types of UDF in [[Microsoft SQL Server]] 2000: [[scalar function]]s, inline table-valued functions, and multistatement table-valued functions.&lt;br /&gt;
&lt;br /&gt;
Scalar functions return a single data value (not a table) with RETURNS clause. Scalar functions can use all scalar data types, with exception of timestamp and user-defined data types. &lt;br /&gt;
Inline table-valued functions return the [[result set]] of a single SELECT statement. &lt;br /&gt;
Multistatement table-valued functions return a table, which was built with many [[Transact-SQL|TRANSACT-SQL]] statements.&lt;br /&gt;
&lt;br /&gt;
User-defined functions can be invoked from a query like built‑in functions such as OBJECT_ID, LEN, DATEDIFF, or can be executed through an EXECUTE statement like stored procedures.&lt;br /&gt;
&lt;br /&gt;
Performance Notes:&lt;br /&gt;
{{olist| On Microsoft SQL Server 2000 a table-valued function which &amp;quot;wraps&amp;quot; a View may be much faster than the View itself. The following MyFunction is an example of a &amp;quot;function-wrapper&amp;quot; which runs faster than the underlying view MyView:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;tsql&amp;quot;&amp;gt;&lt;br /&gt;
CREATE FUNCTION MyFunction()&lt;br /&gt;
    RETURNS @Tbl TABLE &lt;br /&gt;
    (&lt;br /&gt;
        StudentID              VARCHAR(255),&lt;br /&gt;
        SAS_StudentInstancesID INT,&lt;br /&gt;
        Label                  VARCHAR(255),&lt;br /&gt;
        Value                  MONEY,&lt;br /&gt;
        CMN_PersonsID          INT&lt;br /&gt;
    )&lt;br /&gt;
AS&lt;br /&gt;
BEGIN&lt;br /&gt;
    INSERT @Tbl&lt;br /&gt;
    (&lt;br /&gt;
        StudentID,&lt;br /&gt;
        SAS_StudentInstancesID,&lt;br /&gt;
        Label,&lt;br /&gt;
        Value,&lt;br /&gt;
        CMN_PersonsID&lt;br /&gt;
    )&lt;br /&gt;
    SELECT &lt;br /&gt;
        StudentID,&lt;br /&gt;
        SAS_StudentInstancesID,&lt;br /&gt;
        Label,&lt;br /&gt;
        Value,&lt;br /&gt;
        CMN_PersonsID&lt;br /&gt;
    FROM MyView -- where MyView selects (with joins) the same columns from large table(s)&lt;br /&gt;
&lt;br /&gt;
    RETURN&lt;br /&gt;
END&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
| On Microsoft SQL Server 2005 the result of the same code execution is the opposite: view is executed faster than the &amp;quot;function-wrapper&amp;quot;.}}&lt;br /&gt;
&lt;br /&gt;
User-defined functions are subroutines made of one or more Transact-SQL statements that can be used to encapsulate code for reuse. &lt;br /&gt;
It takes zero or more arguments and evaluates a return value. Has both control-flow and DML statements in its body similar to stored procedures.&lt;br /&gt;
Does not allow changes to any Global Session State, like modifications to database or external resource, such as a file or network.&lt;br /&gt;
Does not support output parameter.&lt;br /&gt;
DEFAULT keyword must be specified to pass the default value of parameter.&lt;br /&gt;
Errors in UDF cause UDF to abort which, in turn, aborts the statement that invoked the UDF.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;tsql&amp;quot;&amp;gt;&lt;br /&gt;
CREATE FUNCTION CubicVolume&lt;br /&gt;
-- Input dimensions in centimeters&lt;br /&gt;
(&lt;br /&gt;
    @CubeLength decimal(4,1), &lt;br /&gt;
    @CubeWidth  decimal(4,1),&lt;br /&gt;
    @CubeHeight decimal(4,1)&lt;br /&gt;
)&lt;br /&gt;
    RETURNS decimal(12,3)&lt;br /&gt;
AS&lt;br /&gt;
BEGIN&lt;br /&gt;
  RETURN(@CubeLength * @CubeWidth * @CubeHeight)&lt;br /&gt;
END&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Apache Hive===&lt;br /&gt;
[[Apache Hive]] defines, in addition to the regular user-defined functions (UDF), also user-defined aggregate functions (UDAF) and table-generating functions (UDTF).&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
|first= |last=&lt;br /&gt;
|url=https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF&lt;br /&gt;
|title=LanguageManual UDF - Apache Hive - Apache Software Foundation&lt;br /&gt;
|website=&lt;br /&gt;
|publisher=&lt;br /&gt;
|date=26 June 2015}}&lt;br /&gt;
&amp;lt;/ref&amp;gt; Hive enables developers to create their own custom functions with Java.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
|first= |last=&lt;br /&gt;
|url=https://cwiki.apache.org/confluence/display/Hive/HivePlugins&lt;br /&gt;
|title=HivePlugins - Apache Hive - Apache Software Foundation&lt;br /&gt;
|website=&lt;br /&gt;
|publisher=&lt;br /&gt;
|date=26 June 2015}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Apache Doris===&lt;br /&gt;
Apache Doris, an open-source real-time analytical database, allows external users to contribute their own UDFs written in C++ to it.&amp;lt;ref&amp;gt;{{cite web |title=Apache Doris UDF |url=https://doris.apache.org/docs/dev/ecosystem/udf/contribute-udf?_highlight=udf |access-date=8 April 2023 |archive-date=10 April 2023 |archive-url=https://web.archive.org/web/20230410141729/https://doris.apache.org/docs/dev/ecosystem/udf/contribute-udf/?_highlight=udf |url-status=dead }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*[http://msdn2.microsoft.com/en-us/library/aa258261(SQL.80).aspx Microsoft SQL Server reference for CREATE FUNCTION]&lt;br /&gt;
*[http://dev.mysql.com/doc/refman/5.5/en/adding-functions.html MySQL manual section on UDFs]&lt;br /&gt;
*[http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0000917.html DB2 CREATE FUNCTION statement]&lt;br /&gt;
&lt;br /&gt;
[[Category:Databases]]&lt;br /&gt;
[[Category:SQL]]&lt;br /&gt;
[[Category:Subroutines]]&lt;/div&gt;</summary>
		<author><name>imported&gt;BorgHunter</name></author>
	</entry>
</feed>