Fetching Even and Odd Records in Oracle

Fetching Even and Odd Records in Oracle

This tip will help you understand how to apply the mod function and use it to obtain even and odd records from columns in Oracle.

You basically want to retrieve records in odd and even order based on a column. So, suppose you want to fetch all records with the its value as an odd: (1, 3, 5, 7…). You’d use this line to form the result:

SELECT * FROM TABLENAME WHERE MOD(column_choosen_with_integer_values,2) = 1;

For even records, you’d use:

SELECT * FROM TABLENAME WHERE MOD(column_choosen_with_integer_values,2) = 0;

You can use this same logic to fetch odd and even records in a table using ROWNUM as well.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved