DECLARE statement

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

Syntax
DECLARE variable-name data-type
Remarks

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 with other declarations, such as a cursor declaration (DECLARE CURSOR), immediately following the BEGIN keyword. In a Transact-SQL procedure or trigger, there is no such restriction.

See also
Standards and compatibility
  • SQL/2003   Persistent Stored Module feature.

Example

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

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