dataengref migrate

Home / Oracle

Oracle NVL2 in Snowflake, Databricks and BigQuery

Snowflake and Databricks support NVL2 directly. BigQuery has no NVL2; write IF(expr IS NOT NULL, a, b).

Oracle function: NVL2(expr1, expr2, expr3) · Oracle docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeSame nameNVL2(expr1, expr2, expr3)Returns expr2 if expr1 is not NULL, otherwise expr3.Snowflake docs
DatabricksSame namenvl2(expr1, expr2, expr3)Synonym of CASE WHEN expr1 IS NOT NULL THEN expr2 ELSE expr3 END.Databricks docs
BigQueryRewriteIF(expr1 IS NOT NULL, expr2, expr3)No NVL2 function.BigQuery docs

Behavior differences to check

Examples

Flag customers with an email

Oracle
SELECT id, NVL2(email, 'yes', 'no') AS has_email FROM customers;
Snowflake
SELECT id, NVL2(NULLIF(email, ''), 'yes', 'no') AS has_email FROM customers;
Databricks
SELECT id, nvl2(nullif(email, ''), 'yes', 'no') AS has_email FROM customers;
BigQuery
SELECT id, IF(NULLIF(email, '') IS NOT NULL, 'yes', 'no') AS has_email FROM customers;

Other Oracle functions

Last checked: · Paste a whole query into the SQL checker to find every function that needs a change.