Declaring host variables in embedded SQL applications

To transmit data between the database server and the application, declare host variables in your application source code for things such as relational SQL queries and host variable declarations for XQuery expressions.

About this task

The following table provides examples of host variable declarations for embedded SQL host languages.
Table 1. Host Variable Declarations by Host Language
Language Example Source Code
C and C++
EXEC SQL BEGIN DECLARE SECTION; 
  short     dept=38, age=26; 
  double    salary; 
  char      CH; 
  char      name1[9], NAME2[9]; 
  short     nul_ind; 
EXEC SQL END DECLARE SECTION;
COBOL
 EXEC SQL BEGIN DECLARE SECTION END-EXEC. 
   01 age        PIC S9(4) COMP-5 VALUE 26. 
   01 DEPT       PIC S9(9) COMP-5 VALUE 38. 
   01 salary     PIC S9(6)V9(3) COMP-3. 
   01 CH         PIC X(1). 
   01 name1      PIC X(8). 
   01 NAME2      PIC X(8). 
   01 nul-ind    PIC S9(4) COMP-5. 
 EXEC SQL END DECLARE SECTION END-EXEC.
FORTRAN
       EXEC SQL BEGIN DECLARE SECTION
         integer*2     age   /26/
         integer*4     dept  /38/
         real*8        salary 
         character     ch 
         character*8   name1,NAME2 
         integer*2     nul_ind 
       EXEC SQL END DECLARE SECTION