Indicate null values
- 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.