适用于: Databricks SQL
Databricks Runtime
返回第一个非 NULL 参数。
coalesce(expr1 [, ...] )
结果类型是 参数的最常见类型 。
至少必须有一个参数。
与在调用函数前计算所有参数的常规函数不同,coalesce
从左到右计算参数,直至找到非 NULL 值。
如果所有参数均为 NULL
,则结果为 NULL
。
特殊注意事项适用于 VARIANT
类型。 有关详细信息,请参阅 isnull
函数 。
> SELECT coalesce(NULL, 1, NULL);
1
-- The following example raises a runtime error because the second argument is evaluated.
> SELECT coalesce(NULL, 5 / 0);
Error: DIVISION_BY_ZERO
-- The following example raises no runtime error because the second argument is not evaluated.
> SELECT coalesce(2, 5 / 0);
2
> SELECT coalesce(NULL, 'hello');
hello