Define and use variables

Any variable that you use in an SPL routine, other than a variable that is implicitly defined in the parameter list of the routine, must be defined in the body of the routine.

The value of a variable is held in memory; the variable is not a database object. Therefore, rolling back a transaction does not restore the values of SPL variables.

To define a variable in an SPL routine, use the DEFINE statement. DEFINE is not an executable statement. DEFINE must appear after the CREATE PROCEDURE statement and before any other statements. The examples in the following figure are all legal variable definitions.
Figure 1: Variable definitions.
DEFINE a INT;
DEFINE person person_t;
DEFINE GLOBAL gl_out INT DEFAULT 13;

For more information on DEFINE, see the description in the HCL OneDB™ Guide to SQL: Syntax.

An SPL variable has a name and a data type. The variable name must be a valid identifier, as described in the Identifier segment in the HCL OneDB Guide to SQL: Syntax.