User-defined functions

User-defined functions are small programs that you can write to perform an operation. You can use a user-defined function wherever you can use a built-in function.

The CREATE FUNCTION statement is used to explicitly create a user-defined function.

Example: Assume that you define a distinct type called US_DOLLAR. You might want to allow instances of US_DOLLAR to be added. You can create a user-defined function that uses a built-in addition operation and takes instances of US_DOLLAR as input. This function, called a sourced function, requires no application coding. Alternatively, you might create a more complex user-defined function that can take a US_DOLLAR instance as input and then convert from U.S. dollars to another currency.

You name the function and specify its semantics so that the function satisfies your specific programming needs. You can use a user-defined function wherever you can use a built-in function.