SQL Tutorial SQL Advanced SQL Database SQL References

Oracle REMAINDER() Function



The Oracle (PL/SQL) REMAINDER() function returns the remainder of x divided by y. The function returns the following:

  • If y is 0, then an error is returned.
  • If x or y or both are NULL, then NULL is returned.
  • If x is not 0, then the remainder is y - (x*N) where N is the integer nearest y/x. If y/x is a multiple of 0.5, then N is the nearest even integer.
  • If y is a floating-point number, and if the remainder is 0, then the sign of the remainder is the sign of y. Remainders of 0 are unsigned for NUMBER values.
Note: The MOD() function is similar to REMAINDER() except that it uses FLOOR in its formula, whereas REMAINDER() uses ROUND.

Syntax

REMAINDER(x, y)

Parameters

x Required. Specify the value that will be divided by y.
y Required. Specify the value that will be divided into x.

Return Value

Returns the remainder of x divided by y.

Example 1:

The example below shows the usage of REMAINDER() function.

REMAINDER(12, 3)
Result: 0

REMAINDER(14, 3)
Result: -1

REMAINDER(13.5, 3.1)
Result: 1.1

REMAINDER(13.5, -3.1)
Result: 1.1

Example 2:

Consider a database table called Sample with the following records:

Dataxy
Data 1105
Data 2206
Data 3307
Data 4408
Data 5509

To calculate the remainder of division operation, where records of column x is divided by records of column y, the following query can be used:

SELECT Sample.*, 
REMAINDER(x, y) AS REMAINDER_Value 
FROM Sample;

This will produce the result as shown below:

DataxyREMAINDER_Value
Data 11050
Data 22062
Data 33072
Data 44080
Data 5509-4

❮ Oracle Functions