ARRAY_LAST scalar function
The ARRAY_LAST function returns the maximum array index value of the array.
The schema is SYSIBM.
- array-expression
- An SQL variable, SQL parameter, or global variable of an array type, or a CAST specification of a parameter marker to an array type.
The data type of the result is the data type of the array index, which is INTEGER for an ordinary array. If array-expression is not null and the cardinality of the array is greater than zero, the value of the result is the maximum array index value, which is the cardinality of the array for an ordinary array.
The result can be null; if array-variable is null or the cardinality of the array is zero, the result is the null value.
Examples
- Return the last index value in the ordinary array variable
SPECIALNUMBERS
to the SQL variablePI_CONSTIDX
.
The result is 10.SET PI_CONSTIDX = ARRAY_LAST(SPECIALNUMBERS)
- Given the associative array variable
PHONELIST
with index values and phone numbers: 'Home' is '4163053745', 'Work' is '4163053746', and 'Mom' is '4164789683', assign the value of the maximum index in the array to the character string variable namedX
.
The value of 'Work' is assigned toSET X = ARRAY_LAST(PHONELIST)
X
. Access the element value associated with index value 'Work' and assign it to the SQL variableNUMBER_TO_CALL
:SET NUMBER_TO_CALL = PHONELIST[X]