Progress
Embedded SQL-92
Guide and Reference


Using Indicator Variables with INPUT Host Variables

You can use indicator variables with INPUT host variables. You can assign a NULL value to a column when you INSERT a row into a table or when you UPDATE a table column that allows NULL values.

The code fragment in the following example shows how to declare and use an indicator variable in an INSERT statement. The host variables in this example are: order_no_v, order_date_v, product_v, and qty_v. The indicator variable qty_i is associated with the qty_v host variable. The optional INDICATOR keyword identifies qty_i as an indicator variable.

EXAMPLE

The code fragment illustrates these steps:

  1. DECLARE host variables and one indicator variable in the DECLARE SECTION.
  2. Set the indicator variable to the value -1 in a C Language section; do not prepend a colon in native C Language statements.
  3. INSERT a row into the orders table; set the qty column to NULL; prepend a colon to each host variable and indicator variable in this executable statement.
  4. /*
    ** 1. DECLARE host and indicator variables in the DECLARE SECTION
    */
    EXEC SQL BEGIN DECLARE SECTION ;
     
         long   order_no_v ;
         char   order_date_v[10] 
         char   product_v[5] ;
         long   qty_v ;
         long   qty_i ;
     
    EXEC SQL END DECLARE SECTION ;
     
    /*
    **    C Language processing here, to assign values for order_no_v,
    **    product_v, and to determine qty_v is NULL 
    */
       .
       .
       .
    /*
    ** 2. Set indicator variable qty_i for the qty_v host variable;
    **    Set to -1 to indicate IS NULL, and there is no value in qty_v 
    */
     
    qty_i = -1 ;
     
    /*
    ** 3. INSERT a row in qty column of orders table with qty_v column NULL
    */
     
    EXEC SQL 
         INSERT INTO orders (order_no, product, qty)
         VALUES (:order_no_v, :product_v, :qty_v INDICATOR :qty_i) ; 
    


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095