Previous Topic

Next Topic

Checking Indicator Variables to Test for Returned Null Values

Indicator variables can also be used to test whether a returned value is a null value. This is done by using the indicator variables along with host variables used for output.

The following example shows how to use indicator variables in the INTO clause of a SELECT statement to check for null values.

Example Using Indicator Variables to Check for Returned Null Values


EXEC SQL BEGIN DECLARE SECTION ;
     long    cust_no ;
     char    phone [13] ;
     short   i_phone ;
EXEC SQL END DECLARE SECTION ;

cust_no = 1001 ;
EXEC SQL
     SELECT c_phone
     INTO  :phone:i_phone
     FROM  customer
     WHERE  cust_no = :cust_no ;

if (i_phone == -1)
     printf ("No Phone Number\\n") ;
else
     printf ("Phone Number is %s\\n", phone) ;

For more information on indicator variables, see "NULL Value Handling in ESQL" and "Error Handling in ESQL".