Creating structured types
This topic describes how to create structured types.
A
structured type is a user-defined type that contains one or more attributes,
each of which has a name and a data type of its own. A structured
type can serve as the type of a table or view in which each column
of the table derives its name and data type from one of the attributes
of the structured type. A structured type can also serve as a type
of a column or a type for an argument to a routine.
Before you begin
About this task
To define a structured type to represent a person, with age and address attributes, issue the
following statement:
CREATE TYPE Person_t AS
(Name VARCHAR(20),
Age INT,
Address Address_t)
INSTANTIABLE
REF USING VARCHAR(13) FOR BIT DATA
MODE DB2SQL;
Unlike distinct types, the attributes of structured types can be composed of types other than the
built-in Db2®
data types. The preceding type declaration includes an attribute called Address
whose source type is another structured type, Address_t
.