Indicate null values

When the statement returns a null value to a host variable, the value might not be a meaningful C value. Your program can take one of the following actions:
  • If you have defined an indicator variable for this host variable, sets the indicator variable to -1.

    Your program can check the indicator variable for a value of -1.

  • If you did not define an indicator variable, the runtime behavior of depends on how you compiled the program:
    • If you compile the program with the -icheck preprocessor option, generates an error and sets sqlca.sqlcode to a negative value when the database server returns a null value.
    • If you compile the program without the -icheck option, does not generate an error when the database server returns a null value. In this case, you can use the risnull() function to test the host variable for a null value.

If the value returned to the host variable is not null, sets the indicator variable to 0. If the SQL operation is not successful, the value of the indicator variable is not meaningful. Therefore, check the outcome of the SQL statement before you check for a null value in the host variable.

The NULL keyword of an INSERT statement allows you to insert a null value into a table row. As an alternative to the NULL keyword in an INSERT statement, you can use a negative indicator variable with the host variable.

If you want to insert a variable while the indicator is set to NULL (-1), the indicator value takes precedence over the variable value. The value inserted in this case will NULL instead of the value of the host variable.

When you return aggregate function values into a host variable, keep in mind that when the database server performs an aggregate function on an empty table, the result of the aggregate operation is the null value. The only exception to this rule is the COUNT(*) aggregate function, which returns 0 in this case.
Important: If you activate the DATASKIP feature of the database server, an aggregate function also returns null if all fragments are offline or if all the fragments that are online are empty.