Chapter 9 SQL Statements
605
SET statement
Use this statement to assign a value to a SQL variable.
SET
identifier
=
expression
None.
None.
"CREATE VARIABLE statement" on page 481
"DECLARE statement" on page 487
"DROP VARIABLE statement" on page 513
"Expressions" on page 230
The SET statement assigns a new value to a variable. The variable must have
been previously created using a CREATE VARIABLE statement or
DECLARE statement, or it must be an OUPUT parameter for a procedure.
A variable can be used in a SQL statement anywhere a column name is
allowed. If a column name exists with the same name as the variable, the
variable value is used.
Variables are local to the current connection, and disappear when you
disconnect from the database or use the DROP VARIABLE statement. They
are not affected by COMMIT or ROLLBACK statements.
Variables are necessary for creating large text or binary objects for INSERT
or UPDATE statements from embedded SQL programs, because
embedded SQL host variables are limited to 32,767 bytes.
♦
SQL/92 Persistent stored module feature.
♦
Sybase Not supported. In Adaptive Server Enterprise, variables are
assigned using the SELECT statement with no table, a Transact-SQL
syntax that is also supported by Adaptive Server Anywhere. The SET
statement is used to set database options in Adaptive Server Enterprise.
♦ The following code fragment could be used to insert a large text value
into the database.
Function
Syntax
Permissions
Side effects
See also
Description
Standards and
compatibility
Example