Oracle String Concatenation and NULL Behavior Explained
Oracle treats empty strings as NULL but concatenates them as empty. This exception aids string building but harms portability and safety in checks. This article explains how NULL propagates through most Oracle operators, why concatenation is the sole exception, how SQL Server differs under SET ANSI_NULLS, and why explicit IS NULL and COALESCE handling is safer for cross-database designs.
On this page
Key idea
In Oracle, NULL values propagate through most operators, yielding NULL results. Concatenation is the sole exception, treating NULL operands as empty strings. While convenient for constructing composite values without wrapping functions like NVL, this creates risks for portable logic. Oracle Database treats a character value with a length of zero as null, but warns that this may not continue in future releases and recommends not treating empty strings the same as nulls. Any arithmetic expression containing a null always evaluates to null, and all operators except concatenation return null when given a null operand. To test for nulls, use only IS NULL and IS NOT NULL; other conditions with nulls evaluate to UNKNOWN, and a WHERE clause that evaluates to UNKNOWN returns no rows. SQL Server and others often propagate NULL in comparisons or concatenation depending on settings. Developers should use IS NULL for validation and avoid relying on implicit empty-string behavior in cross-database designs.
Context: Concatenation as an Exception Among Oracle Operators
Oracle Database treats a character value with a length of zero as null. When using standard operators, any expression containing a null evaluates to null. The exception is the concatenation operator, which treats a null operand as an empty string instead of propagating it. For example, 'A' || NULL || 'C' returns 'AC', while 10 + NULL returns NULL. Oracle also warns that treating zero-length characters as null may not continue in future releases, and recommends that you do not treat empty strings the same as nulls. To test for missing data, use only IS NULL or IS NOT NULL; other conditions with nulls evaluate to UNKNOWN, and a WHERE clause that evaluates to UNKNOWN returns no rows.
SELECT 'A' || NULL || 'C' FROM dual;
SELECT 10 + NULL FROM dual;Recommendation: Rely on This When Building Composite Values, But Not for Checks
You can use concatenation to form composite identifiers without wrapping columns in NVL functions. However, do not rely on empty strings representing null in validation logic. Always use IS NULL or IS NOT NULL conditions to test for missing data as recommended by Oracle. Because a null cannot be equal or unequal to any value or to another null, equality comparisons are unreliable for null detection. Explicit handling makes the intent clear and protects queries from subtle changes in how Oracle treats zero-length strings.
Trade-offs: Differences With SQL Server and Portability
SQL Server handles null expressions differently. When SET ANSI_NULLS is ON, comparisons with null return UNKNOWN. When SET ANSI_NULLS is OFF, equals and not equals treat NULL as a known value and return TRUE or FALSE. Other databases often follow standard SQL where null propagates through concatenation. This makes code that assumes Oracle's behavior non-portable without explicit checks. If you move Oracle concatenation logic to PostgreSQL or SQL Server, test the results under the target database's null settings and rewrite with COALESCE or NVL where needed.
Applicability Boundaries
Oracle warns that treating zero-length characters as null may not continue in future releases. Arithmetic expressions still return null if any operand is null. Relying on implicit empty-string handling is not a universal best practice and may break compatibility. Use this concatenation behavior only when you control the target database and understand the risk, and prefer explicit null handling for portable applications.
Applicability
- Does your query rely on NULL being treated as an empty string in concatenation?
- Will this logic break if moved to PostgreSQL or SQL Server?
- Do you use IS NULL or IS NOT NULL for testing null presence?
- Have you considered using COALESCE instead of implicit null handling?
Where this applies
This behavior is non-standard and Oracle warns it may not continue in future releases. Arithmetic operations still return NULL on any NULL operand. Reliance on this feature reduces code portability and safety, especially when moving to PostgreSQL or SQL Server, where NULL handling differs and concatenation may propagate NULL or depend on session settings.