Categories:

Numeric functions

# DIV0NULLÂ¶

Performs division like the division operator (`/`), but returns 0 when the divisor is 0 or NULL (rather than reporting an error or returning NULL).

DIV0

## SyntaxÂ¶

```DIV0NULL( <dividend> , <divisor> )
```

## ArgumentsÂ¶

`dividend`

Numeric expression that evaluates to the value that you want to divide.

`divisor`

Numeric expression that evaluates to the value that you want to divide by.

## ReturnsÂ¶

The quotient. If the divisor is 0 or NULL, the function returns 0.

## ExamplesÂ¶

As shown in the following example, the DIV0NULL function performs division like the division operator (`/`):

```SELECT 1/2;

+----------+
|      1/2 |
|----------|
| 0.500000 |
+----------+
```
```SELECT DIV0NULL(1, 2);

+----------------+
| DIV0NULL(1, 2) |
|----------------|
|       0.500000 |
+----------------+
```

Unlike the division operator, DIV0NULL returns a 0 (rather than reporting an error or returning NULL) when the divisor is 0 or NULL.

```SELECT 1/0;
100051 (22012): Division by zero
```
```SELECT DIV0NULL(1, 0);

+----------------+
| DIV0NULL(1, 0) |
|----------------|
|       0.000000 |
+----------------+
```
```SELECT 1/NULL;

+--------+
| 1/NULL |
|--------|
|   NULL |
+--------+
```
```SELECT DIV0NULL(1, NULL);

+-------------------+
| DIV0NULL(1, NULL) |
|-------------------|
|          0.000000 |
+-------------------+
```
Language: English