Rechercher dans le manuel MySQL
12.3.4 Assignment Operators
Assignment operator. Causes the user variable on the left hand side of the operator to take on the value to its right. The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields a scalar value, including the result of a query (provided that this value is a scalar value). You can perform multiple assignments in the same
SET
statement. You can perform multiple assignments in the same statement.Unlike
=
, the:=
operator is never interpreted as a comparison operator. This means you can use:=
in any valid SQL statement (not just inSET
statements) to assign a value to a variable.- -> 1, 1
- -> 1, 1
- -> 4
- -> 4
You can make value assignments using
:=
in other statements besidesSELECT
, such asUPDATE
, as shown here:- -> 4
- -> 1, 3, 5, 7
- Query OK, 1 row affected (0.00 sec)
- -> 1
- -> 2, 3, 5, 7
While it is also possible both to set and to read the value of the same variable in a single SQL statement using the
:=
operator, this is not recommended. Section 9.4, “User-Defined Variables”, explains why you should avoid doing this.This operator is used to perform value assignments in two cases, described in the next two paragraphs.
Within a
SET
statement,=
is treated as an assignment operator that causes the user variable on the left hand side of the operator to take on the value to its right. (In other words, when used in aSET
statement,=
is treated identically to:=
.) The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields a scalar value, including the result of a query (provided that this value is a scalar value). You can perform multiple assignments in the sameSET
statement.In the
SET
clause of anUPDATE
statement,=
also acts as an assignment operator; in this case, however, it causes the column named on the left hand side of the operator to assume the value given to the right, provided anyWHERE
conditions that are part of theUPDATE
are met. You can make multiple assignments in the sameSET
clause of anUPDATE
statement.In any other context,
=
is treated as a comparison operator.- -> 1, 1
- -> 1, 1
For more information, see Section 13.7.5.1, “SET Syntax for Variable Assignment”, Section 13.2.12, “UPDATE Syntax”, and Section 13.2.11, “Subquery Syntax”.
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-assignment-operators.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.