dataengref migrate

Home / Oracle

Oracle TRUNC (date) in Snowflake, Databricks and BigQuery

Oracle TRUNC(date) without a unit removes the time of day. Snowflake keeps TRUNC for dates, Databricks has trunc and date_trunc, and BigQuery uses DATE_TRUNC. Pass the unit explicitly in every target.

Oracle function: TRUNC(date [, fmt]) · Oracle docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeSame nameTRUNC(date_or_time_expr, date_or_time_part)Same as DATE_TRUNC with the arguments swapped. Units are date parts such as 'MONTH' or 'MM'.Snowflake docs
DatabricksSame nametrunc(expr, unit)Returns a DATE. Use date_trunc(unit, expr) to keep a TIMESTAMP.Databricks docs
BigQueryRewriteDATE_TRUNC(date_expression, MONTH)Use DATETIME_TRUNC or TIMESTAMP_TRUNC for other types.BigQuery docs

Behavior differences to check

Examples

Revenue by month

Oracle
SELECT TRUNC(order_date, 'MM') AS month, SUM(amount) FROM orders GROUP BY TRUNC(order_date, 'MM');
Snowflake
SELECT TRUNC(order_date, 'MM') AS month, SUM(amount) FROM orders GROUP BY 1;
Databricks
SELECT trunc(order_date, 'MM') AS month, SUM(amount) FROM orders GROUP BY 1;
BigQuery
SELECT DATE_TRUNC(order_date, MONTH) AS month, SUM(amount) FROM orders GROUP BY 1;

Other Oracle functions

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