devxlogo

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.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist