All pages
Powered by GitBook
1 of 1

Loading...

SET Variable

Assign values to user-defined variables. This guide explains how to store data in session-specific variables for reuse in subsequent SQL statements.

Syntax

SET var_name = expr [, var_name = expr] ...

Description

The SET statement in is an extended version of the general statement. Referenced variables may be ones declared inside a stored program, global system variables, or user-defined variables.

The SET statement in stored programs is implemented as part of the pre-existing syntax. This allows an extended syntax of SET a=x, b=y, ... where different variable types (locally declared variables, global and session server variables, user-defined variables) can be mixed. This also allows combinations of local variables and some options that make sense only for system variables; in that case, the options are recognized but ignored.

SET can be used with both and .

When setting several variables using the columns returned by a query, should be preferred.

To set many variables to the same value, the function can be used.

Below is an example of how a user-defined variable may be set:

See Also

This page is licensed: GPLv2, originally from

stored programs
SET
SET
local variables
user-defined variables
SELECT INTO
LAST_VALUE( )
SET
SET STATEMENT
DECLARE Variable
fill_help_tables.sql
SET @x = 1;