DB2 Scalar functions - ARRAY_FIRST


Volta a página anterior

Volta ao Menu das scalar functions

Volta ao Menu Principal


Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

ARRAY_FIRST

The ARRAY_FIRST function returns the minimum array index value of the array.

ARRAY_FIRST ( array-expression )

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 minimum array index value, which is 1 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

  1. Return the first index value in the ordinary array variable SPECIALNUMBERS to the SQL variable E_CONSTIDX.
    SET E_CONSTIDX = ARRAY_FIRST(SPECIALNUMBERS)
    The result is 1.

  2. Given the associative array variable PHONELIST with index values and phone numbers:
    'Home' is '4163053745', 'Work' is '4163053746', and 'Mom' is '416-4789683', assign the value of the minimum index in the array to the character string variable named X.
    SET X = ARRAY_FIRST(PHONELIST)
    The value of 'Home' is assigned to X.

    Access the element value associated with index value 'Home' and assign it to the SQL variable NUMBER_TO_CALL:
    SET NUMBER_TO_CALL = PHONELIST[X]

© Copyright IBM Corp.