- · Subtypes specify the same set of operations as their base type, but only a subset of its values.
- · A subtype does not introduce a new type; rather, it places an optional constraint on its base type.
Subtypes can increase reliability and improve readability by indicating the intended use of constants and variables.
Ex: SUBTYPE HIREDate IS DATE NOT NULL;
PL/SQL predefines several Subtypes in package STANDARD.
For example, PL/SQL predefines the subtypes CHARACTER and INTEGER as follows:
SUBTYPE CHARACTER IS CHAR;
SUBTYPE INTEGER IS NUMBER(20,0); -- allows only whole numbers
You can define your own subtypes in the declarative part of any PL/SQL block, subprogram, or package using the syntax
SUBTYPE subtype_name IS base_type[(constraint)] [NOT NULL];
where subtype_name is a type specifier used in subsequent declarations, base_type is any scalar or user-defined PL/SQL datatype, and constraint applies only to base types that can specify precision and scale or a maximum size. Note that a default value is not permitted;