MySQL IS和IS NOT运算符有什么用?
在MySQL中, IS和 ISNOT运算符均用于根据布尔值测试值。
IS运算符的语法可以如下-
Val IS Boolean_val
这里 瓦尔是我们要反对布尔值测试值。
Boolean_val 是将对其进行测试的布尔值,它可以是TRUE,FALSE或UNKNOWN。
ISNOT 运算符的语法可以如下-
Val IS NOT Boolean_val
这里 瓦尔 是我们要反对布尔值测试值。
Boolean_val 是将针对其测试val的布尔值,它可以为TRUE,FALSE或UNKNOWN。
以下MySQL语句将演示以上内容-
mysql> Select 1 IS TRUE, 0 IS FALSE, NULL IS UNKNOWN; +-----------+------------+-----------------+ | 1 IS TRUE | 0 IS FALSE | NULL IS UNKNOWN | +-----------+------------+-----------------+ | 1 | 1 | 1 | +-----------+------------+-----------------+ 1 row in set (0.00 sec) mysql> Select 1 IS NOT TRUE, 0 IS NOT FALSE, NULL IS NOT UNKNOWN; +---------------+----------------+---------------------+ | 1 IS NOT TRUE | 0 IS NOT FALSE | NULL IS NOT UNKNOWN | +---------------+----------------+---------------------+ | 0 | 0 | 0 | +---------------+----------------+---------------------+ 1 row in set (0.00 sec) mysql> Select 0 IS NOT TRUE, 1 IS NOT FALSE, NULL IS NOT UNKNOWN; +---------------+----------------+---------------------+ | 0 IS NOT TRUE | 1 IS NOT FALSE | NULL IS NOT UNKNOWN | +---------------+----------------+---------------------+ | 1 | 1 | 0 | +---------------+----------------+---------------------+ 1 row in set (0.00 sec)