Saturday, 24 August 2013

DB2 Using Host Variables

Any valid host variable name can be used in an SQL statement. Host variables must be declared to the host program before they can be used. Host variables are used by DB2 to
  • Retrieve data and put it into the host variables for use by the application program
  • Insert data into a table or update it from the data in the host variable
  • Evaluate a WHERE or HAVING clause using the data in the host variable
Host variables follow the naming conventions of the host language. A colon (:) must precede host variables used in SQL to tell DB2 that the variable is not a column name. A colon must not precede host variables outside of SQL statements.
In the following example, :CANPHONE and :CIDNO are host variables; the values will be supplied at runtime.
                EXEC SQL
                      UPDATE EMPLOYEE
                              SET PHONE = :EMPPHONE
                              WHERE EMP-ID = :EMPNO
                END-EXEC.

Created with Artisteer

No comments:

Post a comment