Creating currency-based distinct types

This topic describes how to create currency-based distinct types. Suppose that you are writing applications that must handle different currencies. Given that conversions are necessary whenever you want to compare values of different currencies, you want to ensure that Db2® does not allow these currencies to be compared or manipulated directly with one another. Because distinct types are only compatible with themselves, you must define one for each currency that you need to represent.

Before you begin

For the list of privileges required to define distinct types, see the CREATE DISTINCT TYPE statement.

Procedure

To define distinct types representing the euro and the American and Canadian currencies, issue the following statements:
     CREATE DISTINCT TYPE US_DOLLAR AS DECIMAL (9,3) WITH COMPARISONS 
     CREATE DISTINCT TYPE CANADIAN_DOLLAR AS DECIMAL (9,3) WITH COMPARISONS
     CREATE DISTINCT TYPE EURO AS DECIMAL (9,3) WITH COMPARISONS
Note that you must specify the WITH COMPARISONS clause because comparison operators are supported on DECIMAL (9,3).