SQL empty string vs NULL
On Oracle, an empty string IS NULL: comparisons, defaults, concatenation and indexes all behave differently than on every other major engine.
- Categoría
- Strings
- Returns
string- In this category
- 66 of 172
Sintaxis
'' IS NULL -- TRUE on Oracle, FALSE everywhere else
Soporte del motor
| Motor | Support | Notas |
|---|---|---|
| SQL Server | Not built in | No built-in equivalent. |
| PostgreSQL | Not built in | No built-in equivalent. |
| MySQL | Not built in | No built-in equivalent. |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | Sí | '' and NULL are indistinguishable in Oracle SQL |
Ejemplos
Oracle
SELECT CASE WHEN '' IS NULL THEN 'null' ELSE 'empty' END AS verdict FROM dual; -- null
PostgreSQL
SELECT '' IS NULL AS verdict; -- false
Oracle
SELECT COUNT(*) FROM t WHERE note IS NULL; -- counts both true NULLs and '' values
Conviene saberlo
- SELECT CASE WHEN '' IS NULL THEN 'null' ELSE 'empty' END FROM dual gives 'null' on Oracle; there is no empty string value in Oracle SQL.
- Comparisons written elsewhere break: WHERE status = '' matches nothing, and COALESCE(status, '') returns NULL, not ''.
- Concatenation absorbs it: 'a' || '' is 'a' on Oracle (same as elsewhere), but a column set to '' is stored as NULL, which fails NOT NULL constraints.
- Migrations: NULLIF(col, '') and empty-string defaults need Oracle-specific rewrites, usually col IS NULL checks.
Questions about Empty string vs NULL
Why does Oracle say '' IS NULL?
A historical decision: Oracle SQL has no distinct empty-string value. It is documented behaviour, not a bug, and every Oracle string check must account for it.
How do I check for an empty value on Oracle?
col IS NULL: it covers both true NULLs and values written as ''. The col = '' test never matches anything on Oracle.
Do other engines ever blur '' and NULL?
No: PostgreSQL, MySQL, SQL Server and SQLite all keep them distinct. Only Oracle collapses them.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: Oracle.
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.