Contents Index Declaration section [ESQL] DECLARE CURSOR statement [ESQL] [SP]

ASA SQL Reference
  SQL Statements

DECLARE statement


Description 

Use this statement to declare a SQL variable within a compound statement (BEGIN ... END).

Syntax 

DECLARE variable-name data-type

Usage 

Variables used in the body of a procedure, trigger, or batch can be declared using the DECLARE statement. The variable persists for the duration of the compound statement in which it is declared.

The body of a Watcom-SQL procedure or trigger is a compound statement, and variables must be declared immediately following BEGIN. In a Transact-SQL procedure or trigger, there is no such restriction.

Standards and compatibility 
Example 

The following batch illustrates the use of the DECLARE statement and prints a message on the server window:

BEGIN
  DECLARE varname CHAR(61);
  SET varname = 'Test name';
  MESSAGE varname;
END

Contents Index Declaration section [ESQL] DECLARE CURSOR statement [ESQL] [SP]