MariaDB DIV Operator
In MariaDB, DIV is a built-in operator that performs divisions and returns an integer result.
MariaDB DIV Syntax
Here is the syntax of the MariaDB DIV operator:
x DIV y
Operands
x-
Optional. dividend.
y-
Optional. divisor.
Return value
x DIV y returns the integer part of the result of x dividing by y.
If the parameters x or y are not integers, they will be converted to DECIMAL type before calculation.
x DIV 0 will return NULL.
x DIV y will return NULL if x or y is an invalid operand .
MariaDB DIV Examples
Basic example
The following statement shows the basic usage of the MariaDB DIV operator:
SELECT 100 DIV 2, 100 DIV 3;
Output:
+-----------+-----------+
| 100 DIV 2 | 100 DIV 3 |
+-----------+-----------+
| 50 | 33 |
+-----------+-----------+In this example, 100 DIV 3 returns the integer portion of its real result.
divide by zero
x DIV 0 will return NULL.
SELECT 1 DIV 0;
Output:
+---------+
| 1 DIV 0 |
+---------+
| NULL |
+---------+Let’s check the warnings:
SHOW WARNINGS;
Output:
+---------+------+---------------+
| Level | Code | Message |
+---------+------+---------------+
| Warning | 1365 | Division by 0 |
+---------+------+---------------+Conclusion
In MariaDB, DIV is a built-in operator that performs divisions and returns an integer result.