Distinct types
A distinct type is a user-defined data type that is based on existing built-in DB2® data types.
A distinct type is internally the same as a built-in data type, but DB2 treats them as a separate and incompatible type for semantic purposes.
Defining your own distinct type ensures that only functions that are explicitly defined on a distinct type can be applied to its instances.
Although you can have different distinct types that are based on the same built-in data types, distinct types have the property of strong typing. With this property, you cannot directly compare instances of a distinct type with anything other than another instance of that same type. Strong typing prevents semantically incorrect operations (such as explicit addition of two different currencies) without first undergoing a conversion process. You define which types of operations can occur for instances of a distinct type.
If your company wants to track sales in many countries, you must convert the currency for each country in which you have sales.
CREATE DISTINCT TYPE US_DOLLAR AS DECIMAL (9,2);
CREATE DISTINCT TYPE CANADIAN_DOLLAR AS DECIMAL (9,2);
CREATE TABLE US_SALES
(PRODUCT_ITEM_NO INTEGER,
MONTH INTEGER,
YEAR INTEGER,
TOTAL_AMOUNT US_DOLLAR);
CREATE TABLE CANADIAN_SALES
(PRODUCT_ITEM_NO INTEGER,
MONTH INTEGER,
YEAR INTEGER,
TOTAL_AMOUNT CANADIAN_DOLLAR);
User-defined functions support the manipulation of distinct types.