TATECHATLAS
◎ English
Data & databases / Tip

Oracle Empty String Interpreted as NULL and Portability Risks

Oracle treats zero-length character values as NULL, breaking portability and comparison logic; always use IS NULL explicitly.

On this page

In Oracle Database, a character column value with zero length is treated as NULL. This means that a comparison using the equality operator (=) between a column and an empty string '' can return rows that also match IS NULL. However, Oracle explicitly recommends against relying on this equivalence because future releases may stop treating empty strings as NULL. Using = '' therefore introduces portability risk: the same query may behave differently on other SQL platforms or on later Oracle versions. Moreover, empty strings and NULL are not interchangeable in arithmetic or other operations; NULL propagates through expressions while zero is a valid numeric value. To guarantee consistent behavior, always use IS NULL (or IS NOT NULL) to test for nulls, and avoid equating empty strings with nulls in application logic.

Context and Recommendation

Oracle Database documentation states that a character value with a length of zero is treated as null. This behavior is not part of the SQL standard and is specific to Oracle. For portable code, treat empty strings and nulls as distinct values and use IS NULL to test for nulls.

Oracle recommends that you do not treat empty strings the same as nulls, as this may not continue to be true in future releases. Using explicit IS NULL checks ensures that your queries remain correct regardless of version changes.

Causes and Trade-offs

When SET ANSI_NULLS is OFF, Oracle's = operator treats two nulls as equal, but an empty string '' is currently interpreted as null, making = '' behave like IS NULL. If the setting changes or the database is migrated, the semantics shift, potentially breaking existing logic.

Comparing a column to NULL with = always yields UNKNOWN, never TRUE or FALSE. Using = '' exploits Oracle's current zero-length‑to‑null mapping, but this is not guaranteed across platforms such as SQL Server, where = '' does not match null unless ANSI_NULLS is OFF, and even then the behavior differs.

Illustration

The following examples show how an empty string comparison and IS NULL behave in Oracle. Note that results may change in future releases.

Code: SELECT * FROM t WHERE col = '';\nSELECT * FROM t WHERE col IS NULL;

SELECT * FROM t WHERE col = '';\nSELECT * FROM t WHERE col IS NULL;

Applicability

This guidance applies only to Oracle Database; other DBMS products may treat empty strings and nulls differently, and SQL Server's behavior depends on the SET ANSI_NULLS setting.

Future Oracle releases may stop treating empty strings as null, so code that relies on this equivalence may break. Always test with IS NULL and verify behavior after any Oracle version upgrade.

Applicability

  • Oracle currently treats a zero-length character value as null.
  • Using = '' may produce rows that also match IS NULL, but this behavior is not portable.
  • IS NULL is the recommended, portable way to test for nulls in Oracle and most SQL dialects.

The empty‑string‑to‑null mapping is Oracle‑specific and may change in future releases; it does not apply to other database systems without additional configuration.

Sources

  1. Oracle Database: Nulls ↗
  2. Microsoft SQL Server: Comparison Operators ↗
Back to top ↑