在MySQL中,IS和IS NOT操作符都用于将一个值与布尔值进行测试。
IS操作符的语法可以如下所示:
Val IS Boolean_val
HereValis the value that we want to test against Boolean value.
Boolean_valis the Boolean value against which the value would be tested and it can be TRUE, FALSE or UNKNOWN.
The syntax ofIS NOToperator can be as follows −
在这里,Val是我们想要与布尔值进行测试的值。
Boolean_val是要对其进行测试的布尔值,它可以是TRUE、FALSE或UNKNOWN。
IS NOT运算符的语法可以如下所示−
Val IS NOT Boolean_val
在这里,Val是我们想要根据布尔值进行测试的值。
Boolean_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)
Atas ialah kandungan terperinci MySQL的IS和IS NOT运算符有什么用途?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!