Host variables

Use host variables to pass a single data item between DB2® and your application.

A host variable is a single data item that is declared in the host language to be used within an SQL statement. You can use host variables in application programs that are written in the following languages: assembler, C, C++, COBOL, Fortran, and PL/I to perform the following actions:

  • Retrieve data into the host variable for your application program's use
  • Place data into the host variable to insert into a table or to change the contents of a row
  • Use the data in the host variable when evaluating a WHERE or HAVING clause
  • Assign the value that is in the host variable to a special register, such as CURRENT SQLID and CURRENT DEGREE
  • Insert null values into columns by using a host indicator variable that contains a negative value
  • Use the data in the host variable in statements that process dynamic SQL, such as EXECUTE, PREPARE, and OPEN