Retrieving the next and previous array elements
Retrieving the next or previous elements in a simple array can most easily be done by using the ARRAY_PRIOR and ARRAY_NEXT functions.
Before you begin
- Read: Ordinary array data type
- Read: Restrictions on the array data type
- Privileges required to execute the SET statement
About this task
Procedure
Example
firstPhone index 0 1 2 3
phone '416-223-2233' '416-933-9333' '416-887-8887' '416-722-7227'
The following SQL statement sets the variable firstPhone
to the value 0..SET firstPhone = ARRAY_FIRST(phones);
The
following SQL statement sets the variable nextPhone to the value 1.SET nextPhone = ARRAY_NEXT(phones, firstPhone);
The
following SQL statement sets the variable phoneNumber to the value
of the phone number at the next position in the array after nextPhone.
This is the array element value at index value position 2.SET phoneNumber = phones[ARRAY_NEXT(phones, nextPhone)];
What to do next
If the SET statement failed to execute successfully:
- Verify the SQL statement syntax of the SET statement and execute the statement again.
- Verify that the local variable is of the correct data type.
- Verify that the array was created successfully and currently exists.