sql - What is the difference between MOD and REMAINDER in oracle? -
although both functions perform same operation, produce same o/p, basic difference between these two? there performance related difference, if yes, 1 better?
thanks
the documentation pretty clear on difference:
note
the remainder function uses round function in formula, whereas mod function uses floor function in formula.
in other words, when arguments positive integers, mod function returns positive number between 0 , second argument. remainder function returns number absolute value less second argument divided 2.
the differences can more striking negative numbers. 1 example of difference is:
remainder(-15, 4) mod(-15, 4)
the first gives -3
, second 1
.
edit:
what happening here? how many times 4 go -15. 1 method "-4" times remained of 1. is: -15 = 4*(-4) + 1. other "-3" times: -15 = 4*(-3) - 3.
the difference -15/4 expressed integer. using floor, -4
. using round, -3
.
Comments
Post a Comment