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

Randomly select rows from a table


Summary 
If you need to randomly select one or more rows from one of your tables, then you can use the following query. As an example we want to show an employee, randomly selected from the EMP table:
SELECT *
 FROM (SELECT empno, ename
         FROM emp
        WHERE ename like '%'
       ORDER BY DBMS_RANDOM.VALUE)
WHERE rownum <= 1;
     EMPNO ENAME
---------- ----------
      7566 JONES
If you need two employees, use:
SELECT *
 FROM (SELECT empno, ename
         FROM emp
        WHERE ename like '%'
       ORDER BY DBMS_RANDOM.VALUE)
WHERE rownum <= 2;
     EMPNO ENAME
---------- ----------
      7499 ALLEN
      7844 TURNER

No comments:

Post a Comment