Declare a host variable

You must define the data storage that a host variable needs before you can use that variable in Informix® ESQL/C programs. To assign an identifier to the variable and associate it with a data type, you declare the variable.

You declare host variables within the Informix® ESQL/C program as C variables, with the same basic syntax as C variables.

To identify the variable as a host variable, you must declare it in either of the following ways:
  • Put the declarations in an ESQL declare section:
    EXEC SQL BEGIN DECLARE SECTION;
       -- put host variable declarations here
    EXEC SQL END DECLARE SECTION;

    Make sure that you terminate the statements EXEC SQL BEGIN DECLARE SECTION and EXEC SQL END DECLARE SECTION with semicolons.

    Using the EXEC SQL BEGIN DECLARE SECTION and EXEC SQL END DECLARE SECTION keywords conforms to ANSI standards.

  • Preface each declaration with a dollar sign ($).
Within the declaration itself, you must specify the following information:
  • The name of the host variable
  • The data type of the host variable
  • The initial value of the host variable (optional)
  • The scope of the host variable (which the placement of the declaration within the program determines)