3 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊
在SQL中,對(duì)null值和任何其他值(包括其他值)null)使用比較運(yùn)算符(例如=, !=, <,等)會(huì)導(dǎo)致null,被認(rèn)為是false為了WHERE子句的目的(嚴(yán)格地說(shuō),它是“不正確”,而不是“假”,但效果是一樣的)。
理由是null意思是“未知”,所以與null也是“未知”。因此,您將不會(huì)通過(guò)編碼在行上命中。where my_column = null.
SQL提供了用于測(cè)試列是否為null.class=‘class 2’>is null和is not null,這是測(cè)試null(或者不是null).
下面是一些SQL,顯示了各種條件及其效果,如上面所示。
create table t (x int, y int);
insert into t values (null, null), (null, 1), (1, 1);
select 'x = null' as test , x, y from t where x = null
union all
select 'x != null', x, y from t where x != null
union all
select 'not (x = null)', x, y from t where not (x = null)
union all
select 'x = y', x, y from t where x = y
union all
select 'not (x = y)', x, y from t where not (x = y);
只返回一行(如預(yù)期的):
TEST X Y
x = y 1 1

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊
NULL
where x is null
where x = null

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊
null
null
=
null
where x is null
where x = null
添加回答
舉報(bào)