A variable lets you store a single data value that can be used during your session's queries. You can only store a limited set of data types in a variable. These include string, integer, decimal, float, or NULL. If you use a different type in your variable, it will be converted into one of the permitted types listed previously.
Creating and using variables
Learning how to create and assign values to variables
In order to create and assign a value to a variable, you use the SET statement. There are two variations of assigning a value to a variable:
- SET @varname = value;
- SET @varname := value;
You can also set a variable with a SELECT statement, as shown in the following code sample:
SELECT @varname := column1 FROM...