MOD
MOD(N,M)
Section titled “MOD(N,M)”- n: This indicates the dividend. It is the number that is to be divided.
- m: This refers to the divisor. It is the number by which the dividend (N) is to be divided.
Example
Section titled “Example”SELECT MOD(10, 3);Output
Section titled “Output”1Explanation
Section titled “Explanation”The MOD function returns the remainder of a division. In this example, the division of 10 by 3 leaves a remainder of 1, which is the output.
MOD(Y, X)
Section titled “MOD(Y, X)”- y: The dividend in the modulo operation. This is the number that is to be divided.
- x: The divisor in the modulo operation. This is the number by which the dividend will be divided. The result of the MOD(Y, X) function is the remainder of this operation.
Example
Section titled “Example”SELECT MOD(10, 3);Output
Section titled “Output”1Explanation
Section titled “Explanation”The MOD() function in PostgreSQL returns the remainder of the division of the first number by the second number. In this example, 10 divided by 3 equals 3 remainder 1, so MOD(10,3) returns 1.
MOD(dividend INT, divisor INT) RETURNS INT;
Section titled “MOD(dividend INT, divisor INT) RETURNS INT;”- dividend int: This parameter represents the number to be divided. It must be an integer value.
- divisor int: This parameter specifies the number by which the dividend will be divided. It should also be an integer. The function will return the remainder of this division operation.
Example
Section titled “Example”SELECT MOD(10,3) AS Result;Output
Section titled “Output”Result-----------1Explanation
Section titled “Explanation”In the SQL statement provided, the MOD function returns the remainder of the division of 10 by 3 which equals 1.
MOD(N, M)
Section titled “MOD(N, M)”- n: This refers to the dividend. It is the numeric value to be divided in the MOD operation.
- m: This refers to the divisor. It is the numeric value by which the dividend is divided in the MOD operation.
Example
Section titled “Example”SELECT MOD(8, 3)FROM dual;Output
Section titled “Output”2Explanation
Section titled “Explanation”In the provided SQL statement, the MOD function returns the remainder of a division. In this case, dividing 8 by 3 leaves a remainder of 2. Oracle’s dual table is a one-row, one-column table present by default in all Oracle databases, which is used when there is a need for a select statement without an actual table.
MOD(X,Y)
Section titled “MOD(X,Y)”- x: The first numeric value that you wish to apply the modulo operation to. This can be any real number.
- y: The second numeric value to use in the modulo operation. This is the value that ‘X’ will be divided by to derive the remainder. This number should not be zero as it would result in a division error.
Example
Section titled “Example”SELECT MOD(11, 3);Output
Section titled “Output”2Explanation
Section titled “Explanation”The MOD function returns the remainder of the division of the first number by the second. In this case, dividing 11 by 3 gives a quotient of 3 and a remainder of 2. Therefore, MOD(11, 3) returns 2.