与SQL中的NULL比较 [英] Comparisons with NULLs in SQL

查看:267
本文介绍了与SQL中的NULL比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ANSI-92 SQL要求与NULL的比较评估为虚假",例如:

ANSI-92 SQL mandates that comparisons with NULL evaluate to "falsy," eg:

SELECT * FROM table WHERE field = NULL
SELECT * FROM table WHERE field != NULL

将不返回任何行,因为无法像这样比较NULL.相反,必须使用谓词IS NULLIS NOT NULL:

Will both return no rows because NULL can't be compared like that. Instead, the predicates IS NULL and IS NOT NULL have to be used instead:

SELECT * FROM table WHERE field IS NULL
SELECT * FROM table WHERE field IS NOT NULL

研究表明,Oracle 1 ,PostgreSQL,MySQL和SQLite均支持ANSI语法.将DB2和Firebird添加到该列表.

Research has shown me that Oracle 1, PostgreSQL, MySQL and SQLite all support the ANSI syntax. Add to that list DB2 and Firebird.

除了关闭了ANSI_NULLS的SQL Server之外,还有哪些其他RDBMS支持非ANSI语法?

Aside from SQL Server with ANSI_NULLS turned off, what other RDBMS support the non-ANSI syntax?

1 整个空字符串= NULL混乱.

1 The whole empty string = NULL mess notwithstanding.

推荐答案

这里很好比较SQLite,PostgreSQL,Oracle,Informix,DB2,MS-SQL,OCELOT,MySQL 3.23.41,MySQL 4.0.16,Firebird,SQL Anywhere和Borland Interbase中的空处理

Here is a nice comparison of null handling in SQLite, PostgreSQL, Oracle, Informix, DB2, MS-SQL, OCELOT, MySQL 3.23.41, MySQL 4.0.16, Firebird, SQL Anywhere, and Borland Interbase

这篇关于与SQL中的NULL比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆