Pages

OracleEBSpro is purely for knowledge sharing and learning purpose, with the main focus on Oracle E-Business Suite Product and other related Oracle Technologies.

I'm NOT responsible for any damages in whatever form caused by the usage of the content of this blog.

I share my Oracle knowledge through this blog. All my posts in this blog are based on my experience, reading oracle websites, books, forums and other blogs. I invite people to read and suggest ways to improve this blog.


Thursday, August 18, 2016

Selecting only even or odd records

Summary 
First create a table(RANDOM_VALUES) with 100 records of random values.
CREATE TABLE RANDOM_VALUES (ID NUMBER(3), col1 VARCHAR2(30));

BEGIN
    FOR i IN 1..100 LOOP
      INSERT INTO RANDOM_VALUES VALUES (i, ROUND(Dbms_Random.VALUE*100000));
    END LOOP;
    COMMIT;
  END;
  /
To select the even records from table execute
SELECT * FROM 
(SELECT ROWNUM num, ID, col1 FROM RANDOM_VALUES) 
WHERE MOD(num,2) = 0;
To select the odd records from table execute
SELECT * FROM 
(SELECT ROWNUM num, ID, col1 FROM RANDOM_VALUES) 
WHERE MOD(num,2) = 1;

No comments:

Post a Comment