You can define variables and refer to their values. You can also refer to environment variables, and there is a built-in variable that contains the result of the most recent SQL statement.
To define a variable, use the
let $a= 14; let $b= this is a string; --let $a= 14 --let $b= this is a string
The variable name cannot contain whitespace or the
If a variable has a numeric value, you can increment or decrement the value:
inc $a; dec $a; --inc $a --dec $a
dec are commonly
while loops to modify the value of a
counter variable that controls loop execution.
The result from executing a query can be assigned to a variable by
enclosing the query within backtick
let $q= `select version()`;
References to variables can occur in the
system commands. Variable references are
replaced by their values. As of MySQL 5.0.26/5.1.12, a nonquery
value assigned to a variable in a
also can refer to variables.
As of MySQL 4.1.23/5.0.42/5.1.18, variable references that occur
expanded before the query is sent to the server for execution.
You can refer to environment variables. For example, this command
displays the value of the
$PATH variable from
$mysql_errno is a built-in variable that
contains the numeric error returned by the most recent SQL
statement sent to the server, or 0 if the command executed
$mysql_errno has a value of
–1 if no statement has yet been sent.
Copyright © 2006, 2014, Oracle and/or its affiliates. All rights reserved. Legal Notices