3 回答

TA貢獻1818條經驗 獲得超3個贊
在SQL中,對null值和任何其他值(包括其他值)null)使用比較運算符(例如=, !=, <,等)會導致null,被認為是false為了WHERE子句的目的(嚴格地說,它是“不正確”,而不是“假”,但效果是一樣的)。
理由是null意思是“未知”,所以與null也是“未知”。因此,您將不會通過編碼在行上命中。where my_column = null.
SQL提供了用于測試列是否為null.class=‘class 2’>is null和is not null,這是測試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);
只返回一行(如預期的):
TEST X Y
x = y 1 1

TA貢獻1802條經驗 獲得超4個贊
NULL
where x is null
where x = null

TA貢獻1860條經驗 獲得超9個贊
null
null
=
null
where x is null
where x = null
添加回答
舉報