Creating an array data type is a task that you would perform
as a prerequisite to creating a variable of the array data type.
Before you begin
Before
you create an array data type, ensure that you have the privileges
required to execute the CREATE TYPE statement.
About this task
Array
data types can only be created in SQL PL contexts where execution
of the CREATE TYPE statement is supported.
Restrictions
See: Restrictions on the array data type
Procedure
- Define the CREATE TYPE statement
- Specify a name for the array data type.
- Specify the AS keyword followed by the keyword name
for the data type of the array element. For example, INTEGER, VARCHAR.
- Specify the ARRAY keyword and the domain of the subindices
in the array. For example, if you specify 100, the valid indices will
be from 1 to 100.
This number is the same as the cardinality
of the array - the number of elements in the array.
- Execute the CREATE TYPE statement from a supported interface.
Results
The CREATE type statement should execute successfully and
the array type should be created.
Example
Example 1:
CREATE TYPE simpleArray AS INTEGER ARRAY[100];
This array data type can contain up to 100 integer values
indexed by integer values ranging from 1 to 100.
Example
2:
CREATE TYPE id_Phone AS VARCHAR(20) ARRAY[100];
This array data type can contain up to 100 phone values
stored as VARCHAR(20) data type values indexed by integer values ranging
from 1 to 100.
What to do next
After
creating the array data type you can declare an array
variable.