Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (Français) » SQL Anywhere Server - SQL Reference » Using SQL » SQL statements » SQL statements (A-D)


DECLARE statement

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 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.


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

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