Data access with host-variable arrays
A host-variable array is a data array that is declared in a host language for use within an SQL statement. You can retrieve data into host-variable arrays for use by your application program. You can also place data into host-variable arrays to insert rows into a table.
You can specify host-variable arrays in C, C++, COBOL, or PL/I. Each host-variable array contains values for a column, and each element of the array corresponds to a value for a column. You must declare the array in the host program before you use it.
Host-variable arrays can be referenced only as a simple reference in the following contexts. In syntax diagrams, host-variable-array designates a reference to a host-variable array.
- In a FETCH statement for a multiple-row fetch. See FETCH statement.
- In the FOR n ROWS form of the INSERT statement with a host-variable array for the source data. See INSERT statement.
- In a MERGE statement with multiple rows of source data. See MERGE statement.
- In an EXECUTE statement to provide a value for a parameter marker in a dynamic FOR n ROWS form of the INSERT statement or a MERGE statement. See EXECUTE statement.
Host-variable arrays are defined by statements of the host language, as explained in the following topics:
Example
The following statement uses the main host-variable array, COL1, and the corresponding indicator array, COL1IND. Assume that COL1 has 10 elements. The first element in the array corresponds to the first value, and so on. COL1IND must have at least 10 entries.
EXEC SQL
SQL FETCH FIRST ROWSET FROM C1 FOR 5 ROWS
INTO :COL1 :COL1IND
END-EXEC.