例如,()适用于sqllite3:
()
sqllite3
select * from orders where custid = ? and status in ()
但是它失败了postgres:
postgres
ksysdb=# select code, applicable_objecttype from pssystem_ktagtype where applicable_objecttype in (); ERROR: syntax error at or near ")" LINE 1: ...pe from pssystem_ktagtype where applicable_objecttype in ();
使用(null)使postgres感到高兴,并且似乎不打扰sqllite3:
(null)
ksysdb=# select code, applicable_objecttype from pssystem_ktagtype where applicable_objecttype in (null); code | applicable_objecttype ------+----------------------- (0 rows)
但是它可以在SQL Server和Oracle上运行吗?ANSI SQL有什么要说的?我的猜测是null永远不会匹配任何东西(包括null它自己),因此 in列表 条件将始终评估为false。
null
IN (NULL)在Postgres,SQL Server,Oracle,MariaDB,MySQL和SQLite中应该没问题。至少我无法在SQL Fiddle或db <> fiddle上产生任何错误。
IN (NULL)
设置:
CREATE TABLE a (a varchar(1)); INSERT INTO a (a) VALUES ('a'); SELECT * FROM a WHERE a IN (NULL);