Using host-variable arrays in SQL statements

Use host-variable arrays in embedded SQL statements to represent values that the program does not know until the query is executed. Host-variable arrays are useful for storing a set of retrieved values or for passing a set of values that are to be inserted into a table.

To use a host-variable array in an SQL statement, specify any valid host-variable array that is declared according to the host language rules. You can specify host-variable arrays in C or C++, COBOL, and PL/I. You must declare the array in the host program before you use it.

Host-variable arrays are defined by statements of the host language, as explained in the following topics:

Tip: Host-variable arrays are not supported for assembler, FORTRAN, or REXX programs. However, you can use SQL descriptor areas (SQLDA) to achieve similar results in any host language. For more information see Defining SQL descriptor areas (SQLDA).

Where host-variable arrays can be used

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.

Start of changeIf an application references a host-variable array in other contexts that are not supported, Db2 returns the SQLCODE -312 error.End of change