Randomly select rows from a table
                                                 Last update (2008-02-17 22:16:59)
                                                                                                                   Date added (2008-02-17 22:15:26)

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

    
Reviews
Filters
Search