// conditional reference

SQL NULL value

The marker for a missing or unknown value, and the source of most SQL surprises.

类别
条件
Returns
no type
In this category
32 of 43

语法

x IS NULL | x IS NOT NULL

引擎支持

引擎Support备注
SQL Server 是 Supported under this name.
PostgreSQL 是 Supported under this name.
MySQL 是 Supported under this name.
SQLite 是 Supported under this name.
Oracle 是 Supported under this name.

示例

PostgreSQL

SELECT CASE WHEN NULL = NULL THEN 'equal' ELSE 'unknown' END AS result;

Any engine

SELECT * FROM users WHERE deleted_at IS NULL;

值得了解

  • NULL = NULL is UNKNOWN; nothing equals NULL, including another NULL.
  • '' and NULL are different in PostgreSQL, MySQL, SQL Server and SQLite, but Oracle treats a zero-length string AS NULL.
  • Aggregates skip NULLs: AVG and SUM over an empty or all-NULL group return NULL; COUNT returns 0.
  • String concatenation splits: CONCAT('a', NULL) is 'a' in PostgreSQL, SQL Server, SQLite and Oracle but NULL in MySQL; 'a' || NULL is NULL in PostgreSQL, SQLite and SQL Server 2025 but 'a' in Oracle, which treats the NULL as an empty string.

Questions about NULL

Is NULL zero or empty string?

Neither: it is 'unknown'. Zero and '' are values; NULL is the absence of one, with its own logic.

How do I test for NULL?

IS NULL and IS NOT NULL only; = NULL is always UNKNOWN.

Why does my AVG ignore rows?

AVG skips NULL values by design; use COALESCE(col, 0) if missing should count as zero.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.