SET Statement [ESQL]

Assigns a value to a SQL variable.

Syntax

SET identifier = expression

Examples

Usage

The SET statement assigns a new value to a variable that was previously created using the CREATE VARIABLE statement.

You can use a variable in a SQL statement anywhere a column name is allowed. If there is no column name that matches the identifier, the database server checks to see if there is a variable that matches, and uses its value.

Variables are local to the current connection, and disappear when you disconnect from the database or when you use DROP VARIABLE. 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.

See also Reference: Building Blocks, Tables, and Procedures > SQL Language Elements > Expressions.

Standards

  • SQL—ISO/ANSI SQL compliant.

  • 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 Sybase IQ. The SET statement is used to set database options in Adaptive Server Enterprise.

Permissions

None

Related reference
CREATE VARIABLE Statement
DROP VARIABLE Statement