Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > SELECT >

Using Array Variables with the INTO Clause

In ESQL/C, if you use a DECLARE statement with a SELECT statement that contains an INTO clause, and the variable is an array element, you can identify individual elements of the array with integer literals or variables. The value of the variable that is used as a subscript is determined when the cursor is declared; the subscript variable subsequently acts as a constant.

The following ESQL/C code example declares a cursor for a SELECT ... INTO statement using the variables i and j as subscripts for the array a. After you declare the cursor, the INTO clause of the SELECT statement is equivalent to INTO a[5], a[2].

i = 5
j = 2
EXEC SQL declare c cursor for
   select order_num, po_num into :a[i], :a[j] from orders
      where order_num =1005 and po_num =2865

You can also use program variables in the FETCH statement to specify an element of a program array in the INTO clause. The program variables are evaluated at each fetch, rather than when you declare the cursor.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]