mariadbHow to use variables in Mariadb?
Variables in MariaDB are used to store values for use in SQL statements. Variables can be declared and assigned values using the SET
statement.
Example
SET @myvar = 10;
This statement declares a variable @myvar
and assigns it the value 10
.
The parts of the code are:
SET
: the keyword used to declare and assign values to variables@myvar
: the name of the variable=
: the operator used to assign a value to a variable10
: the value assigned to the variable
Variables can be used in SQL statements in place of literal values. For example:
SELECT * FROM mytable WHERE mycolumn = @myvar;
This statement will select all rows from the table mytable
where the column mycolumn
has the value 10
.
Helpful links
More of Mariadb
- How to check version of Mariadb?
- How to get current year in Mariadb?
- Mariadb partitioning example
- What type to use for a year in Mariadb?
- Mariadb procedure example
- How to use the WITH clause in Mariadb?
- How to use UUID in Mariadb?
- How to work with XML in Mariadb?
- How to list users in Mariadb?
See more codes...