Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
May 31, 2006

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.

MS Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap