What if the program retrieves a NULL value?
NULL values can be stored in the database, but the data types that programming languages support do not recognize a NULL state. A program must have some way to recognize a NULL item to avoid processing it as data.
EXEC SQL SELECT paid_date
INTO :op_date:op_d_ind
FROM orders
WHERE order_num = $the_order;
if (op_d_ind < 0) /* data was null */
rstrdate ('01/01/1900', :op_date);
Because the value might be NULL, an indicator variable named op_d_ind is associated with the host variable. (It must be declared as a short integer elsewhere in the program.)
Following execution of the SELECT statement, the program tests the indicator variable for a
negative value. A negative number (usually -1
) means that the value retrieved into
the main variable is NULL. If the variable is NULL, this program uses the library function to assign a default value to
the host variable. (The function rstrdate is part of the product.)
The syntax that you use to associate an indicator variable with a host variable differs with the language you are using, but the principle is the same in all languages.