Saturday, 24 August 2013

DB2 Host Variables and Structures

A host variable is a data item declared in the host language for use within an SQL statement. Using host variables, you can
  • Retrieve data into the host variable for your application program's use
  • Place data into the host variable to insert into a table or to change the contents of a row
  • Use the data in the host variable when evaluating a WHERE or HAVING clause
  • Assign the value in the host variable to a special register, such as CURRENT SQLID and CURRENT DEGREE
  • Insert null values in columns, using a host indicator variable that contains a negative value
  • Use the data in the host variable in statements that process dynamic SQL, such as EXECUTE, PREPARE, and OPEN  
A host structure is a group of host variables that an SQL statement can refer to using a single name. You can use host structures in all languages except REXX.
Use the host language statements to define the host structures. In some languages, such as C, the program variables that are used as host variables must be defined in a section of the program that is delimited by BEGIN DECLARE SECTION and END DECLARE SECTION statements, as follows:
   EXEC SQL BEGIN DECLARE SECTION;
   DECLARE DB2USER1.TEST_TABLE
       CHAR    NUMBER[7];
       CHAR    NAME[51];
       SHORT LENGTH;
   EXEC SQL END DECLARE SECTION;


Created with Artisteer

No comments:

Post a Comment