Arithmetic with distinct type operands
A distinct type cannot be used with arithmetic operators even if its source data type is numeric.
To perform an arithmetic operation, create a function with the
arithmetic operator as its source. For example, if there were distinct
types INCOME and EXPENSES, both of which had DECIMAL(8,2) data types,
the following user-defined function, REVENUE, could be used to subtract
one from the other.
CREATE FUNCTION REVENUE ( INCOME, EXPENSES )
RETURNS DECIMAL(8,2) SOURCE "-" ( DECIMAL, DECIMAL)
Alternately, the - (minus) operator could be overloaded using a
function to subtract the new data types.
CREATE FUNCTION "-" ( INCOME, EXPENSES )
RETURNS DECIMAL(8,2) SOURCE "-" ( DECIMAL, DECIMAL)
Alternatively, the distinct type can be cast to a built-in data type and the result used as an operand of an arithmetic operator.