Uses of the modulo operator: How Oracle mod can make your life easier.

Uli Bethke Oracle

You may ask, what the heck is modulo? Well, below is an easy to understand definition.

"Modulo basically means keep taking the second number away from the first number. When you can't do it any more without going into negative numbers, whatever's left is the answer"
Ok. That is great. But how can we actually benefit from this.

What are common use cases?

Use case 1: Wrap values such as in a clock, e.g. convert seconds to hours, minutes, seconds.

 Use case 2: Finding even or odd numbers

Use case 3: Expressing something in decimal form

Use case 4: Distribute a dataset into buckets in a round robin fashion

An example would be to update only every second or third record in a table that contains a sequenced list of items. If you don't have a sequence you can use rownum.

Selecting 2/3 of records

Use case 5: Get last M digits from a number

Get the last digit:

Get the last two digits:

and so on.

Let me know how you use the mod operator to make your life easier.

Teach me Big Data to Advance my Career

About the author

Uli Bethke LinkedIn Profile

Uli has 18 years’ hands on experience as a consultant, architect, and manager in the data industry. He frequently speaks at conferences. Uli has architected and delivered data warehouses in Europe, North America, and South East Asia. He is a traveler between the worlds of traditional data warehousing and big data technologies.

Uli is a regular contributor to blogs and books, holds an Oracle ACE award, and chairs the the Hadoop User Group Ireland. He is also a co-founder and VP of the Irish chapter of DAMA, a non for profit global data management organization. He has co-founded the Irish Oracle Big Data User Group.