User-defined distinct types
A user-defined distinct type (UDT) is a mechanism to extend DB2® capabilities beyond the built-in data types that are available.
User-defined distinct types enable you to define new data types to DB2, which gives you considerable power because you are no longer restricted to using the system-supplied built-in data types to model your business and capture the semantics of your data. Distinct data types allow you to map on a one-to-one basis to existing database types.
These benefits are associated with UDTs:
- Extensibility.
By defining new types, you can indefinitely increase the set of types provided by DB2 to support your applications.
- Flexibility.
You can specify any semantics and behavior for your new type by using user-defined functions (UDFs) to augment the diversity of the types available in the system.
- Consistent behavior.
Strong typing ensures that your UDTs will behave appropriately. It guarantees that only functions defined on your UDT can be applied to instances of the UDT.
- Encapsulation.
The behavior of your UDTs is restricted by the functions and operators that can be applied on them. This provides flexibility in the implementation since running applications do not depend on the internal representation that you chose for your type.
- Extensible behavior.
The definition of user-defined functions on types can augment the functionality provided to manipulate your UDT at any time.
- Foundation for object-oriented extensions.
UDTs are the foundation for most object-oriented features. They represent the most important step toward object-oriented extensions.
- Defining a UDT
You define a user-defined type (UDT) using the CREATE DISTINCT TYPE statement.
- Defining tables with UDTs
After you have defined several user-defined types (UDTs), you can start defining tables with columns whose types are UDTs.
- Manipulating UDTs
Strong typing is an important concept associated with user-defined types (UDTs). Strong typing guarantees that only functions and operators defined on a UDT can be applied to its instances.
- Examples: Using UDTs
These examples show the use of user-defined types (UDTs) in various situations.
Parent topic:
Processing special data types
Related concepts
User-defined types