EasyManua.ls Logo

Sybase Adaptive Server Anywhere - Variables

Sybase Adaptive Server Anywhere
1182 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Variables
250
Variables
Adaptive Server Anywhere supports three levels of variables:
Local variables These are defined inside a compound statement in a
procedure or batch using the DECLARE statement. They exist only
inside the compound statement.
Connection-level variables These are defined with a CREATE
VARIABLE statement. They belong to the current connection, and
disappear when you disconnect from the database or when you use the
DROP VARIABLE statement.
Global variables These are system-supplied variables that have
system-supplied values.
Local and connection-level variables are declared by the user, and can be
used in procedures or in batches of SQL statements to hold information.
Global variables are system-supplied variables that provide system-supplied
values. All global variables have names beginning with two @ signs. For
example, the global variable @@version has a value that is the current
version number of the database server. Users cannot define global variables.
Local variables
Local variables are declared using the DECLARE statement, which can be
used only within a compound statement (that is, bracketed by the BEGIN and
END keywords). The variable is initially set as NULL. The value of the
variable can be set using the SET statement, or can be assigned using a
SELECT statement with an INTO clause.
The syntax of the DECLARE statement is as follows:
DECLARE
variable-name
data-type
Local variables can be passed as arguments to procedures, as long as the
procedure is called from within the compound statement.
The following batch illustrates the use of local variables.
BEGIN
DECLARE local_var INT ;
SET local_var = 10 ;
MESSAGE ’local_var = ’, local_var TO CLIENT;
END
Running this batch from Interactive SQL gives the message local_var =
10 in the Interactive SQL Messages window.
Examples

Table of Contents

Related product manuals