Return an empty string if the input is NULL, otherwise return the input unchanged.
EMPTYIFNULL(expr)
## Overview Returns the empty string `''` when the input is NULL and returns the input unchanged otherwise. Use this function to build safe string concatenations that do not produce NULL when one or more operands are missing, or to satisfy a downstream NOT NULL string column. EMPTYIFNULL is the inverse of NULLIFEMPTY. ## Behavior - Returns `''` if the input is NULL. - Returns the input unchanged otherwise. - Deterministic and side effect free. - Operates on the string value; no collation or locale is consulted. ## Compatibility - Semantically equivalent to `COALESCE(expr, '')`, but expressed as a single-argument helper that pairs with NULLIFEMPTY.
| Name | Type | Description |
|---|---|---|
expr | Specifies the string expression to evaluate. Returns '' when the value is NULL; otherwise returns the value unchanged. |
-- NULL becomes an empty string
SELECT EMPTYIFNULL(NULL); -- ''
-- Non-NULL passes through
SELECT EMPTYIFNULL('hello'); -- 'hello'
-- Safe concatenation when middle_name may be NULL
SELECT first_name || ' ' || EMPTYIFNULL(middle_name) || ' ' || last_name AS full_name
FROM hr.catalog.employees;
-- Contrast with NULLIFEMPTY (they are inverses)
SELECT EMPTYIFNULL(NULL) AS e, NULLIFEMPTY('') AS n; -- '' and NULL
-- Emit consistent output for a NOT NULL display column
SELECT EMPTYIFNULL(description) AS description FROM crm.catalog.customers;