Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to efficiently select random rows from a large table ?

783956Jul 10 2010 — edited Jul 11 2010
Hello,

The following code will select 5 rows out of a random set of rows from the emp (employee) table
select * 
  from (
       select ename, job
         from emp
       order by dbms_random.value()
        )
where rownum <= 5
my concern is that the inner select will cause a table scan in order to assign a random value to each row. This code when used against a large table can be a performance problem.

Is there an efficient way of selecting random rows from a table without having to do a table scan ? (I am new to Oracle, therefore it is possible that I am missing a very simple way to perform this task.)

thank you for your help,

John.

Edited by: 440bx on Jul 10, 2010 6:18 PM
This post has been answered by SomeoneElse on Jul 10 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 8 2010
Added on Jul 10 2010
2 comments
9,989 views