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
- What type to use for a year in Mariadb?
- How to use XA transactions in Mariadb?
- Mariadb partitioning example
- How to work with XML in Mariadb?
- How to change wait_timeout in Mariadb?
- How to use window functions in Mariadb?
- How to list users in Mariadb?
- How to view Mariadb logs?
- How to use the WITH clause in Mariadb?
- How to use UUID in Mariadb?
See more codes...