Defining a UDT
You define a user-defined type (UDT) using the CREATE DISTINCT TYPE statement.
For the CREATE DISTINCT TYPE statement, note that:
- The name of the new UDT can be a qualified or an unqualified name.
- The source type of the UDT is the type used by the system to internally represent the UDT. For this reason, it must be a built-in data type. Previously defined UDTs cannot be used as source types of other UDTs.
As part of a UDT definition, the system always generates cast functions to:
- Cast from the UDT to the source type, using the standard name of the source type. For example, if you create a distinct type based on FLOAT, the cast function called DOUBLE is created.
- Cast from the source type to the UDT.
These functions are important for the manipulation of UDTs in queries.
The function path is used to resolve any references to an unqualified type name or function, except if the type name or function is the main object of a CREATE, DROP, or COMMENT ON statement.
- Example: Money
Suppose that you are writing applications that handle different currencies and want to ensure that DB2 does not allow these currencies to be compared or manipulated directly with one another in queries.
- Example: Resumé
Suppose that you want to keep the application forms that are filled out by applicants to your company in a table, and that you are going to use functions to extract information from these forms.
Parent topic:
User-defined distinct types
Related reference
Using qualified function references
CREATE DISTINCT TYPE