HELPLIB.HLB  —  SQLPRE72  Example
    Example 1: Embedding a compound statement in a host language
    program

    The following example shows how to embed a multistatement
    procedure in a program. The keyword PROCEDURE does not appear
    in an embedded SQL application.

    EXEC SQL BEGIN DECLARE SECTION ;
       int   x ;
    EXEC SQL END DECLARE SECTION ;

    EXEC SQL
       BEGIN
          DECLARE :y INTEGER ;

          SET :y = 2 * :x ;  -- :x is a host variable

          UPDATE employees
          SET salary = :y ;
          WHERE .
                .
                . ;

             BEGIN
                DECLARE :x INTEGER ;

                SET :x = 100 ; -- :x is a local variable

                UPDATE employees
                SET salary = :x ;
                WHERE .
                      .
                      . ;
             END ;

       END ;
Close Help