how to select even and odd records from a table in oracle?

To select even and odd records from a table in oracle first we create a Student table with 7 records. for even and odd record there we are execute query at order by id;

select * from Student;

ID

NAME

DPTNAME

LOCATION

         1

       Santosh

                     IT

                Mumbai

         2

        Aman

                   MECH

                Bangalore

         3

        Ravi

                    CS

                 Pune

         4

        Vijay

                    EC

                 Chennai

         5

        Pankaj

                    EC

                 Chennai

         9

         Sany

                  MECH

                  Mumbai

        8

        Anand

                    IT

                 Hyderabad

To find the even number of row details in table :-

select * from (select id,name,dptname,location from student order by id)where mod(id,2)=0;

ID

NAME

DPTNAME

LOCATION

       2

       Aman

           MECH

        Bangalore

       4

       Vijay

           EC

        Chennai

       8

       Anand

           IT

        Hyderabad

To find the odd number of row details in table :-

select * from (select id,name,dptname,location from student order by id)where mod(id,2)<>0;

ID

NAME

DPTNAME

LOCATION

       1

     Santosh

              IT

         Mumbai

       3

     Ravi

             CS

         Pune

       5

     Pankaj

             EC

         Chennai

       9

     Sany

             MECH

         Mumbai

Leave a Comment

Your email address will not be published. Required fields are marked *