Retrieving array values using an index

Retrieving array element values can be done directly by referencing the array and specifying a sub-index value.

Before you begin

The following are prerequisites to this task:

About this task

You would perform this task within SQL PL code in order to access values stored within an array. You might access the array element value as part of an assignment (SET) statement or directly within an expression.

Procedure

  1. Define a SET statement.
    1. Specify a variable name of the same data type as the array element.
    2. Specify the assignment symbol, "=".
    3. Specify the name of the array, square brackets, and within the square brackets an index value.
  2. Execute the SET statement.

Example

The following is an example of a SET statement that retrieves an array value:
SET mylocalVar = myArray[1];

What to do next

If the SET statement executes successfully, the local variable should contain the array element value.

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 variable is of the same data type as the array element.
  • Verify that the array was created successfully and currently exists.