Reference Guide > TDV SQL Script > SQL Script Statement Reference > DECLARE Variable
 
DECLARE Variable
You can define a noncursor variable in SQL Script by specifying its name and data type, and initializing it with a default value. See DECLARE CURSOR of Type Variable for defining cursor variables.
Syntax
DECLARE <variableName>[,…] <dataType> DEFAULT <valueExpression>]
Remarks
DEFAULT initializes the variable.
You can declare more than one variable at a time, provided all the variables are of the same data type but each has a unique name.
The <valueExpression> can use IN parameters, variables declared previously in this block, and any variables in parent blocks. In the current block, the value expression cannot use variables that are defined later. If the value expression’s type does not match the variable’s type, an implicit cast is performed (if possible). See SQL Script Procedure Header for information on IN parameters.
Any variable that is not initialized with a DEFAULT clause has the value NULL.
If the evaluation of the value expression causes an exception, declared variables that have not yet been initialized are set to NULL before entering the exception handler.