MariaDB MOD() Function

In MariaDB, MOD() is a built-in function that performs a modulo operation on two given numeric arguments and returns the result.

MariaDB MOD() Syntax

Here is the syntax of the MariaDB MOD() function:

MOD(number1, number2)

You can also do this with the modulo operators:

number1 MOD number2
number1 % number2

Parameters

number1

Required. The dividend.

number2

Required. The divisor.

If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' 3)' at line 1.

Return value

The MariaDB MOD() function returns the result of the modulo operation of two given numeric arguments.

If number2 equals 0, the MOD() function will return NULL.

If the parameter number is NULL, the MOD() function will return NULL.

MariaDB MOD() Examples

This statement shows the basic usage of the MariaDB MOD() function:

SELECT
    MOD(100, 7),
    MOD(100, 10),
    100 MOD 7,
    100 MOD 10,
    100 % 7,
    100 % 10,
    MOD(0, 1),
    MOD(1, 0),
    MOD(NULL, 1)\G

Output:

 MOD(100, 7): 2
MOD(100, 10): 0
   100 MOD 7: 2
  100 MOD 10: 0
     100 % 7: 2
    100 % 10: 0
   MOD(0, 1): 0
   MOD(1, 0): NULL
MOD(NULL, 1): NULL

Conclusion

In MariaDB, a MOD() built-in function that performs a modulo operation on two given numeric arguments and returns the result.