/ (slash sign) operator
Applies to: Databricks SQL
Databricks Runtime
Returns dividend divided by divisor.
Syntax
dividend / divisor
Arguments
dividend: A numeric orINTERVALexpression.divisor: A numeric expression.
Returns
If both dividend and divisor are DECIMAL, the result is DECIMAL.
If dividend is a year-month interval, the result is an INTERVAL YEAR TO MONTH.
If divident is a day-time interval, the result is an INTERVAL DAY TO SECOND.
In all other cases, a DOUBLE.
If the divisor is 0, the operator returns a DIVIDE_BY_ZERO error.
Use try_divide to return NULL on division-by-zero.
注記
In Databricks Runtime, if spark.sql.ansi.enabled is false, the function returns NULL instead of a divide-by-zero error.
Examples
SQL
> SELECT 3 / 2;
1.5
> SELECT 2L / 2L;
1.0
> SELECT INTERVAL '3:15' HOUR TO MINUTE / 3
0 01:05:00.000000
> SELECT 3 / 0;
Error: DIVIDE_BY_ZERO