Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between MOD and REMAINDER in oracle?

Tags:

sql

oracle11g

Although both the functions perform the same operation, even they produce same o/p, what is basic difference between these two? Is there any performance related difference, if yes, then which one is better?

Thanks

like image 279
user3440567 Avatar asked Jun 27 '14 10:06

user3440567


People also ask

What is MOD in Oracle?

This function takes as arguments any numeric datatype or any nonnumeric datatype that can be implicitly converted to a numeric datatype. Oracle determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that datatype, and returns that datatype.

What is MOD in PL SQL?

The MOD function is an inbuilt function in PLSQL which is used to return the remainder when a is divided by b. Its formula is . Syntax: MOD(a, b)

What is remainder in SQL?

The MOD() function in MySQL is used to find the remainder of one number divided by another. The MOD() function returns the remainder of dividend divided by divisor. if the divisor is zero, it returns NULL.

What is MOD in syntax?

MOD(number, divisor) The MOD function syntax has the following arguments: Number Required. The number for which you want to find the remainder. Divisor Required.


1 Answers

The difference between MOD and REMAINDER function can be understood in the example below:

MOD(13,5): returns 3 whereas, REMAINDER (13,5) returns -2

A simple way to understand the difference is that MOD uses the floor function therefore it counts the occurrence of the second number within the first and returns what is left to complete the first number i.e. 2(5) gives 10 adding 3 gives 13 therefore MOD(13,5)=3

However, the REMAINDER uses a Round function it therefore gets the total number of the second number that could make up the first and then subtract the what makes it excess. i.e. 3(5) = 15 and subtracting 2 gives 13,therefore REMAINDER(13,5)= -2

REMAINDER (-15, 4): 4(-4) gives -16 and adding +1 gives -15 hence REMAINDER (-15,4)=+1

MOD (-15, 4): 3(-4) gives -12, adding -3 gives us -15 hence MOD(15,4)=-3

like image 171
Tamunosiki Avatar answered Sep 18 '22 16:09

Tamunosiki