BEGIN DECLARE SECTION statement
The BEGIN DECLARE SECTION statement marks the beginning of an SQL declare section. An SQL declare section contains declarations of host variables that are eligible to be used as host variables in SQL statements in a program.
Invocation for BEGIN DECLARE SECTION
This statement can only be embedded in an application program. It is not an executable statement. It must not be specified in Java™ or REXX.
Authorization for BEGIN DECLARE SECTION
None required.
Syntax for BEGIN DECLARE SECTION
Description for BEGIN DECLARE SECTION
The BEGIN DECLARE SECTION statement can be coded in the application program wherever variable declarations can appear in accordance with the rules of the host language. It is used to indicate the beginning of a host variable declaration section. A host variable section ends with an END DECLARE SECTION statement, described in END DECLARE SECTION statement.
The following rules are enforced by the precompiler only if the host language is C or the STDSQL(YES) SQL processing option is specified:
- A variable referred to in an SQL statement must be declared within a host variable declaration section of the source program in all host languages, other than Java and REXX. Furthermore, the declaration of each variable must appear before the first reference to the variable. Host variables are declared without the use of these statements in Java, and they are not declared at all in REXX.
- BEGIN DECLARE SECTION and END DECLARE SECTION statements must be paired and must not be nested.
- Host variable declaration sections can contain only host variable declarations, SQL INCLUDE statements that include host variable declarations, or DECLARE VARIABLE statements.
Notes for BEGIN DECLARE SECTION
Host variable declaration sections are only required if the STDSQL(YES) option is specified or the host language is C. However, declare sections can be specified for any host language so that the source program can conform to IBM® SQL. If declare sections are used, but not required, variables declared outside a declare section must not have the same name as variables declared within a declare section.
If you are using the Db2 precompiler, ensure that the names of host variables and host-variable arrays are unique within the program, even if the variables and variable arrays are in different blocks, classes, procedures, functions, or subroutines. You can qualify the names with a structure name to make them unique.
Example for BEGIN DECLARE SECTION
EXEC SQL BEGIN DECLARE SECTION;
-- host variable declarations
EXEC SQL END DECLARE SECTION;
