A user-defined function is a mechanism with which you can write your own extensions to SQL. The built-in functions supplied with DB2 are a useful set of functions, but they may not satisfy all of your requirements. For a complete list of the functions supplied with DB2, refer to the "Supported Functions" table in the SQL Reference.
Methods, like UDFs, enable you to write your own extensions to SQL by defining the behavior of SQL objects. However, unlike UDFs, you can only associate a method with a structured type stored as a column in a table.
You may need to extend SQL for the following reasons:
The function specific to your application does not exist in DB2. Whether the function is a simple transformation, a trivial calculation, or a complicated multivariate analysis, you can probably use a UDF to do the job.
The DB2 built-in function does not quite permit the variations that you wish to include in your application.
Many of the programs at your site implement the same basic set of functions, but there are minor differences in all the implementations. Thus, you are unsure about the consistency of the results you receive. If you correctly implement these functions once, in a UDF, then all these programs can use the same implementation directly in SQL and provide consistent results.
As discussed in User-defined Distinct Types and Working with Complex Objects: User-Defined Structured Types, distinct types and structured types can be very useful in extending the capability and increasing the safety of DB2. You can create methods that define the behavior for structured types stored in columns. You can also create functions that act on distinct types.