Creating distinct types
A user-defined distinct type is a data type derived from an existing type, such as an integer, decimal, or character type. To define a distinct type, you use the CREATE DISTINCT TYPE statement.
Before you begin
Instances of the same distinct type can be compared to each other, if the WITH COMPARISONS clause is specified on the CREATE DISTINCT TYPE statement (as in the example in the procedure). If the source data type is a large object, LONG VARCHAR, or LONG VARGRAPHIC type, the WITH COMPARISONS clause cannot be specified.
For the list of privileges required to define distinct types, see the CREATE DISTINCT TYPE statement.About this task
Procedure
To define a distinct type, issue the CREATE DISTINCT TYPE
statement, specifying a type name and the source type.
For example, the following statement defines a new distinct type
called T_EDUC that contains SMALLINT values:
CREATE DISTINCT TYPE T_EDUC AS SMALLINT WITH COMPARISONS
Because the distinct type defined in the preceding statement is based on SMALLINT, the WITH COMPARISONS parameters must be specified.
Results
After you create a distinct type, you can use it to define
columns in a CREATE TABLE statement:
CREATE TABLE EMPLOYEE
(EMPNO CHAR(6) NOT NULL,
FIRSTNME VARCHAR(12) NOT NULL,
LASTNAME VARCHAR(15) NOT NULL,
WORKDEPT CHAR(3),
PHONENO CHAR(4),
PHOTO BLOB(10M) NOT NULL,
EDLEVEL T_EDUC)
IN RESOURCE