Logical Operators
880
This happens because MySQL reads
9223372036854775808.0
in an integer context. The integer
representation is not good enough to hold the value, so it wraps to a signed integer.
12.3.3. Logical Operators
Table 12.4. Logical Operators
Name
Description
AND
,
&&
[880]
Logical AND
NOT
,
!
[880]
Negates value
||
,
OR
[881]
Logical OR
XOR
[881]
Logical XOR
In SQL, all logical operators evaluate to
TRUE
,
FALSE
, or
NULL
(
UNKNOWN
). In MySQL, these are
implemented as 1 (
TRUE
), 0 (
FALSE
), and
NULL
. Most of this is common to different SQL database
servers, although some servers may return any nonzero value for
TRUE
.
MySQL evaluates any nonzero, non-
NULL
value to
TRUE
. For example, the following statements all
assess to
TRUE
:
mysql>
SELECT 10 IS TRUE;
-> 1
mysql>
SELECT -10 IS TRUE;
-> 1
mysql>
SELECT 'string' IS NOT NULL;
-> 1
•
NOT
[880]
,
!
[880]
Logical NOT. Evaluates to
1
if the operand is
0
, to
0
if the operand is nonzero, and
NOT NULL
returns
NULL
.
mysql>
SELECT NOT 10;
-> 0
mysql>
SELECT NOT 0;
-> 1
mysql>
SELECT NOT NULL;
-> NULL
mysql>
SELECT ! (1+1);
-> 0
mysql>
SELECT ! 1+1;
-> 1
The last example produces
1
because the expression evaluates the same way as
(!1)+1
.
Note that the precedence of the
NOT
[880]
operator changed in MySQL 5.0.2. See
Section 12.3.1,
“Operator Precedence”
.
•
AND
[880]
,
&&
[880]
Logical AND. Evaluates to
1
if all operands are nonzero and not
NULL
, to
0
if one or more operands
are
0
, otherwise
NULL
is returned.
mysql>
SELECT 1 && 1;
-> 1
mysql>
SELECT 1 && 0;
-> 0
mysql>
SELECT 1 && NULL;
-> NULL
mysql>
SELECT 0 && NULL;
-> 0
mysql>
SELECT NULL && 0;
-> 0
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...