Declare a host variable
You must define the data storage that a host variable needs before you can use that variable in 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 program as C variables, with the same basic syntax as C variables.
- 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 ($).
- 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)