Performs safe division that returns NULL instead of an error when the divisor is zero.
FLOAT64Diperbarui: 13 Jun 2026SAFE_DIVIDE(dividend, divisor)The number to be divided
The number to divide by
1 SELECT 2 SAFE_DIVIDE(10, 2) as normal_div, 3 SAFE_DIVIDE(10, 0) as div_by_zero, 4 10 / NULLIF(0, 0) as traditional_way;
Comparison of SAFE_DIVIDE with the traditional approach.
| normal_div | div_by_zero | traditional_way |
|---|---|---|
| 5.0 | NULL | NULL |
1 SELECT 2 campaign, 3 conversions, 4 clicks, 5 SAFE_DIVIDE(conversions, clicks) * 100 as conversion_rate 6 FROM `project.dataset.campaigns`;
Calculates conversion rate without worrying about zero clicks.
Sudah paham SAFE_DIVIDE? Latih langsung di browser
Latihan interaktif, langsung di browser.