Using indicator variables with host input variables

When you associate an indicator variable with an input variable, you must explicitly set the indicator variable, using the values in the following table as a guide.

Table 4-3: Indicator variable values used with input variable

Value

Meaning

-1

Treat the corresponding input as a null value.

0

Assign the value of the host variable to the column.

You must supply host language code to test for a null input value and set the indicator variable to -1. This informs Client-Library of a null value. When you set the indicator variable to -1, null is used regardless of the host variable’s actual value.

The following example demonstrates associating an indicator variable with an input variable. The database royalty column is set to a null value because indic is set to -1. Changing the value of indic changes the value of royalty.

exec sql begin declare section;
 CS_SMALLINT     indic;
 CS_INT          royalty;
 exec sql end declare section;
  
 indic = -1;
 exec sql update titles set royalty = :royalty
     :indic where pub_id = "0736";