Oracle to Databricks: function mapping
5 of 15 common Oracle functions need a change in Databricks. Mapping table with Databricks syntax and behavior differences.
Other targets: Oracle to Snowflake · Oracle to BigQuery
Needs a rewrite (5)
No Databricks function with the same behavior; use the construct shown.
| Oracle | Databricks | Notes |
|---|---|---|
| CONNECT BY | Rewrite WITH RECURSIVE cte AS (anchor UNION ALL recursive_step) | Databricks SQL and Databricks Runtime 17.0 and later; recursion stops at 100 levels unless MAX RECURSION LEVEL is set. LEVEL, SYS_CONNECT_BY_PATH and ORDER SIBLINGS BY have no direct form; carry a level counter and a path string in the CTE and order by the path. |
| DUAL | Rewrite SELECT expr | The FROM clause is optional in a SELECT. Sequences read with seq.NEXTVAL FROM DUAL need a different mechanism in each target (Snowflake sequences, identity columns in Databricks, GENERATE_UUID or ROW_NUMBER in BigQuery). |
| ROWNUM | Rewrite LIMIT n / row_number() OVER (ORDER BY ...) | QUALIFY is supported as well. Oracle assigns ROWNUM before ORDER BY, so WHERE ROWNUM <= 10 ... ORDER BY x returns 10 arbitrary rows sorted afterwards. Decide whether the old query meant that or "top 10 by x" before translating it to LIMIT. |
| SYSDATE | Rewrite current_timestamp() | getdate() and now() are synonyms. Use current_date() for the date only. Oracle SYSDATE returns the operating system time of the database server. If that server ran in a local time zone, expressions such as TRUNC(SYSDATE) mean "today in local time" and will shift by hours in a UTC warehouse. Oracle date arithmetic such as SYSDATE - 1 (one day earlier) does not carry over to Databricks or BigQuery; use dateadd or DATETIME_SUB with an explicit unit. |
| TO_CHAR | Rewrite date_format(expr, 'yyyy-MM-dd HH:mm:ss') | Java-style patterns: 'YYYY-MM-DD HH24:MI:SS' becomes 'yyyy-MM-dd HH:mm:ss'. to_char also accepts dates in Databricks Runtime 14.1 and above, with the same patterns. Oracle MI (minutes) and MM (month) map to mm and MM in Databricks. Copying the Oracle model unchanged produces wrong output instead of an error in many cases. Oracle fill mode (FM) and NLS parameters for month names have no exact equivalent; check any format that uses FM, MONTH or DAY with known dates. TO_CHAR on numbers with format models such as '999,999.00' also differs per target; test it separately from date formats. |
Works as written (10)
The same call runs, but check the notes for behavior differences.
| Oracle | Databricks | Notes |
|---|---|---|
| ADD_MONTHS | Same name add_months(startDate, numMonths) | Returns a DATE. Clamps to the end of the month only when the day does not exist. Oracle ADD_MONTHS(DATE '2022-02-28', 1) returns 2022-03-31 because Feb 28 is the last day of February. Databricks and BigQuery return 2022-03-28. Month-end schedules (billing, accruals) are where this shows up. |
| DECODE | Same name decode(expr, key1, value1 [, ...] [, defValue]) | NULL matches NULL. Not to be confused with decode(bin, charset), which decodes binary data. |
| INSTR | Same name instr(str, substr) | Two arguments only; locate(substr, str, pos) adds a start position. INSTR(s, x, -1) (last occurrence) has no direct form; use length(s) - instr(reverse(s), reverse(x)) - length(x) + 2, or a regular expression. |
| LISTAGG | Same name listagg([ALL | DISTINCT] expr [, delimiter]) [WITHIN GROUP (ORDER BY ...)] | Databricks SQL and Databricks Runtime 16.4 and later. On older runtimes use array_join(collect_list(expr), delimiter), which does not guarantee order. ON OVERFLOW TRUNCATE and ON OVERFLOW ERROR are Oracle only; remove the clause and check the target size limit instead. |
| MONTHS_BETWEEN | Same name months_between(expr1, expr2 [, roundOff]) | Fraction based on 31 days per month, rounded to 8 digits unless roundOff is false. Results are rounded to 8 decimal places by default, so equality checks against Oracle values may fail in the last digits. |
| NVL | Same name nvl(expr1, expr2) | Synonym of coalesce(expr1, expr2). Oracle stores '' as NULL, so NVL(col, 'n/a') also replaces empty strings there. In the targets an empty string is not NULL; use NVL(NULLIF(col, ''), 'n/a') to keep the Oracle result. Oracle NVL converts expr2 to the type of expr1. The targets use a common type of both arguments, which can change numeric precision or string length in the result. |
| NVL2 | Same name nvl2(expr1, expr2, expr3) | Synonym of CASE WHEN expr1 IS NOT NULL THEN expr2 ELSE expr3 END. Oracle treats '' as NULL, so NVL2(col, 'set', 'empty') returns 'empty' for empty strings there. Add NULLIF(col, '') in the targets to keep that result. |
| REGEXP_SUBSTR | Same name regexp_substr(str, regexp) | Two arguments only and the whole match. For a group use regexp_extract(str, regexp, idx). REGEXP_SUBSTR(s, 'x=(\\d+)', 1, 1, NULL, 1) becomes regexp_extract(s, 'x=(\\d+)', 1). |
| TO_DATE | Same name to_date(expr, 'yyyy-MM-dd') | Java-style patterns: 'YYYY-MM-DD' becomes 'yyyy-MM-dd'. Use try_to_date to get NULL instead of an error. TO_DATE('2025-03-01 14:30', 'YYYY-MM-DD HH24:MI') keeps 14:30 in Oracle. The targets drop the time when parsing to DATE, so parse to a timestamp type when the time matters. Copying the Oracle model unchanged ('YYYY-MM-DD') parses week-based years and day-of-year in Java patterns and gives wrong dates; always use lower-case yyyy and dd. |
| TRUNC (date) | Same name trunc(expr, unit) | Returns a DATE. Use date_trunc(unit, expr) to keep a TIMESTAMP. TRUNC(d) with no unit means 'DD' in Oracle. In the targets, write CAST(d AS DATE) or pass 'DAY'. Oracle format models such as 'IW' (ISO week) and 'Q' map to the target's WEEK or ISOWEEK and QUARTER parts; check week starts. |