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. A nonquery value assigned to a variable
let command can also refer to variables.
Variable references that occur within
` are 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 statement executed
$mysql_errno has a value of
–1 if no statement has yet been sent.
From MySQL 5.5.17,
contains the symbolic name of the last error, or an empty string
if there was no error.
Copyright © 2006, 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices