DECLARE statement
Function
Syntax
Description
Standards and
compatibility
Examples
Use this statement to declare a SQL variable within a compound statement
(BEGIN ... END).
DECLARE variable_name data-type
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.
♦
SQL/92
Persistent Stored Module feature.
♦
Supported by Adaptive Server Enterprise.
Sybase
♦
To be compatible with Adaptive Server Enterprise, the variable
name must be preceded by an @.
♦
In Adaptive Server Enterprise, a variable that is declared in a
procedure or trigger exists for the duration of the procedure or
trigger. In Adaptive Server Anywhere, if a variable is declared
inside a compound statement, it exists only for the duration of that
compound statement (whether it is declared in a Watcom-SQL or
Transact-SQL compound statement).
♦
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 name;
END
Chapter 9 SQL Statements
487
Need help?
Do you have a question about the Adaptive Server Anywhere and is the answer not in the manual?
Questions and answers