Previous Topic

Next Topic

Inserting Null Values With Indicator Variables

To insert a null value in the table, the application program has to set the indicator variable to negative one and then execute an INSERT or UPDATE c-treeSQL statement specifying the indicator variable.

The following example shows the declaration and usage of an indicator variable (qty_i) to insert a null value into the orders table.

Example Using Indicator Variables to Insert Null Values


...
EXEC SQL BEGIN DECLARE SECTION ;

long order_no_v ;
  char order_date_v [10] ;
  char product_v [5] ;
  long qty_v ;
  short qty_i ;

EXEC SQL END DECLARE SECTION ;

/* set indicator variable for qty */
 /* as -1 for inserting null  */
 qty_i = -1 ;

...

EXEC SQL
  INSERT INTO orders (order_no, product, qty)
  VALUES (:order_no_v, :product_v, :qty_v:qty_i) ;
 ...