Assignment Operators
881
•
OR
[881]
,
||
[881]
Logical OR. When both operands are non-
NULL
, the result is
1
if any operand is nonzero, and
0
otherwise. With a
NULL
operand, the result is
1
if the other operand is nonzero, and
NULL
otherwise.
If both operands are
NULL
, the result is
NULL
.
mysql>
SELECT 1 || 1;
-> 1
mysql>
SELECT 1 || 0;
-> 1
mysql>
SELECT 0 || 0;
-> 0
mysql>
SELECT 0 || NULL;
-> NULL
mysql>
SELECT 1 || NULL;
-> 1
•
XOR
[881]
Logical XOR. Returns
NULL
if either operand is
NULL
. For non-
NULL
operands, evaluates to
1
if an
odd number of operands is nonzero, otherwise
0
is returned.
mysql>
SELECT 1 XOR 1;
-> 0
mysql>
SELECT 1 XOR 0;
-> 1
mysql>
SELECT 1 XOR NULL;
-> NULL
mysql>
SELECT 1 XOR 1 XOR 1;
-> 1
a XOR b
is mathematically equal to
(a AND (NOT b)) OR ((NOT a) and b)
.
12.3.4. Assignment Operators
Table 12.5. Assignment Operators
Name
Description
=
[882]
Assign a value (as part of a
SET
statement, or as part of the
SET
clause in an
UPDATE
statement)
:=
[881]
Assign a value
•
:=
[881]
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
=
[882]
, the
:=
[881]
operator is never interpreted as a comparison operator. This means
you can use
:=
[881]
in any valid SQL statement (not just in
SET
statements) to assign a value to a
variable.
mysql>
SELECT @var1, @var2;
-> NULL, NULL
mysql>
SELECT @var1 := 1, @var2;
-> 1, NULL
mysql>
SELECT @var1, @var2;
-> 1, NULL
mysql>
SELECT @var1, @var2 := @var1;
-> 1, 1
mysql>
SELECT @var1, @var2;
-> 1, 1
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...