dataengref migrate

Home / Oracle

Oracle DECODE in Snowflake, Databricks and BigQuery

Snowflake and Databricks support Oracle-style DECODE, including NULL matching NULL. BigQuery has no DECODE; rewrite it as a CASE expression and handle NULL explicitly.

Oracle function: DECODE(expr, search, result [, search, result]... [, default]) · Oracle docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeSame nameDECODE(expr, search1, result1 [, ...] [, default])A NULL expr matches a NULL search value, as in Oracle.Snowflake docs
DatabricksSame namedecode(expr, key1, value1 [, ...] [, defValue])NULL matches NULL. Not to be confused with decode(bin, charset), which decodes binary data.Databricks docs
BigQueryRewriteCASE expr WHEN search1 THEN result1 ... ELSE default ENDA simple CASE never matches NULL; add WHEN expr IS NULL THEN ... first.BigQuery docs

Behavior differences to check

BigQuery

Examples

Status code to label

Oracle
SELECT order_id, DECODE(status, 'P', 'pending', 'S', 'shipped', NULL, 'none', 'other') AS status_label FROM orders;
Snowflake
SELECT order_id, DECODE(status, 'P', 'pending', 'S', 'shipped', NULL, 'none', 'other') AS status_label FROM orders;
Databricks
SELECT order_id, decode(status, 'P', 'pending', 'S', 'shipped', NULL, 'none', 'other') AS status_label FROM orders;
BigQuery
SELECT order_id, CASE WHEN status IS NULL THEN 'none' WHEN status = 'P' THEN 'pending' WHEN status = 'S' THEN 'shipped' ELSE 'other' END AS status_label FROM orders;

Other Oracle functions

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