CREATE TYPE (Define type)
Function
CREATE TYPE defines an abstract data type.
Privileges
A user can define abstract data types that will be owned by that user.
Format
CREATE TYPE [authorization-identifier.]data-type-identifier
[subtype-clause]
[default-constructor-option]
[member-list]
subtype-clause::=UNDER [authorization-identifier.]data-type-identifier
default-constructor-option::=CONSTRUCTOR {PRIVATE|PROTECTED|PUBLIC}
member-list::=(member[,member]...)
member::={attribute-definition|routine-declaration}
attribute-definition::=[encapsulation-level]
attribute-name data-type [NO SPLIT]
encapsulation-level::= {PRIVATE|PROTECTED|PUBLIC}
routine-declaration::=[encapsulation-level] routine-body
routine-body::={function-body|procedure-body}
Operands
A subtype clause is specified when what is being defined is a subtype that will inherit a specified abstract data type. The subtype clause is used to specify the authorization identifier and data type identifier of the abstract data type that will become the super-type for the abstract data type being defined.
Specifying a subtype clause causes all the attributes and routines defined in the super-type to be inherited by the abstract data type that is being defined.
Specifies the encapsulation level for the default constructor function. The default is PRIVATE.
For the default constructor function, a function that has the same name as the defined abstract data type is defined. The default constructor function takes no arguments. This function returns values of an abstract data type in which null values are set for the attributes of the abstract data type.
Specifies an attribute that makes up the abstract data type.
The routine declaration is where the routine in which data manipulations are specified is written. The same encapsulation levels as for attribute definition are applicable to routine declarations.
Write the function or procedure in the routine body. For details about functions and procedures, see CREATE [PUBLIC] FUNCTION (Define function, define public function) or CREATE [PUBLIC] PROCEDURE (Define procedure, define public procedure) in this chapter.
Common rules
Table 3-43 Data lengths
Category | Data type | Date length (bytes) |
---|---|---|
Numeric data | INTEGER (4-byte binary integer) | 4 |
SMALLINT (two-byte binary integer) | 2 | |
[LARGE] DECIMAL [m, n]# (packed decimal floating-point number) | ![]() ![]() | |
FLOAT (8-byte floating point number) | 8 | |
SMALLFLT (4-byte floating point number) | 4 | |
Character data | CHARACTER[n] (n-byte fixed-length character string) | n |
VARCHAR[n] (n-byte variable-length character string) | 35 | |
National character data | NCHAR[n] (n-character fixed-length national character string) | 2n |
NVARCHAR[n] (n-character variable-length national character string) | 35 | |
Mixed character data | MCHAR[n] (n-byte fixed-length mixed character string) | n |
MVARCHAR[n] (n-byte variable-length mixed character string) | 35 | |
Date data | DATE (date) | 4 |
Date interval data | INTEVAL YEAR TO DAY (date interval) | 5 |
Time data | TIME (time) | 3 |
Time interval data | INTERVAL HOUR TO SECOND (time interval) | 4 |
Time stamp data | TIMESTAMP[p] (fractional second with p digits) (time stamp) | 7 + p/2 |
Large object data | BLOB (binary string in n bytes) | 35 |
Abstract data | User-defined data type defined in CREATE TYPE | 35 |
Notes