Rechercher dans le manuel MySQL
13.6.4.2 Local Variable Scope and Resolution
The scope of a local variable is the
BEGIN ...
END
block within which it is declared. The variable
can be referred to in blocks nested within the declaring block,
except those blocks that declare a variable with the same name.
Because local variables are in scope only during stored program
execution, references to them are not permitted in prepared
statements created within a stored program. Prepared statement
scope is the current session, not the stored program, so the
statement could be executed after the program ends, at which
point the variables would no longer be in scope. For example,
SELECT ... INTO
cannot be used as
a prepared statement. This restriction also applies to stored
procedure and function parameters. See
Section 13.5.1, “PREPARE Syntax”.
local_var
A local variable should not have the same name as a table
column. If an SQL statement, such as a
SELECT ...
INTO
statement, contains a reference to a column and a
declared local variable with the same name, MySQL currently
interprets the reference as the name of a variable. Consider the
following procedure definition:
MySQL interprets xname
in the
SELECT
statement as a reference
to the xname
variable
rather than the xname
column. Consequently, when the procedure
sp1()
is called, the
newname
variable returns the value
'bob'
regardless of the value of the
table1.xname
column.
Similarly, the cursor definition in the following procedure
contains a SELECT
statement that
refers to xname
. MySQL interprets this as a
reference to the variable of that name rather than a column
reference.
Traduction non disponible
Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-local-variable-scope.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.