Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Oracle MOD and SQL Server modulus (%) behavior

user-ryofnSep 28 2023 — edited Sep 28 2023

Hi Everyone,

I'm trying to understand why a simple behavior is not giving any good result.

Scenario is the following, using MOD in Oracle, and % in SQL Server, to emulate the ‘modulo’ function.

However, doing some testing, Oracle results in 15 as the output value in this case:

Oracle query: SELECT MOD((TO_NUMBER('99999999')), 23 + 1) FROM DUAL;

Oracle result: 15

and following the same example on SQL Server gives another result, where this is the one that is expected to have:

SQL Server query : SELECT CAST('99999999' AS NUMERIC) % 23 + 1

SQL Server result: 2

Can someone help me to understand, why the behavior for this function in Oracle and SQL Server is responding different:

https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/MOD.html#GUID-E12A3928-2C50-45B0-B8C3-82432C751B8C

https://learn.microsoft.com/en-us/sql/t-sql/language-elements/modulo-transact-sql?view=sql-server-ver16

Best regards,

user-ryofn

This post has been answered by mathguy on Sep 28 2023
Jump to Answer
Comments
Post Details
Added on Sep 28 2023
4 comments
2,024 views