0% found this document useful (0 votes)
42 views1 page

Returning N Random Records From A Table

This document discusses how to return a random sample of records from a database table using built-in Oracle functions. It shows using DBMS_RANDOM.VALUE to randomly order records, then selecting the top few based on ROWNUM to limit the results to a random sample of rows.

Uploaded by

sreejtih
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views1 page

Returning N Random Records From A Table

This document discusses how to return a random sample of records from a database table using built-in Oracle functions. It shows using DBMS_RANDOM.VALUE to randomly order records, then selecting the top few based on ROWNUM to limit the results to a random sample of rows.

Uploaded by

sreejtih
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Returning n Random Records from a Table

Use the built-in function VALUE, found in the built-in package DBMS_RANDOM, in conjunction
with ORDER BY and the built-in function ROWNUM:

1 select *
2 from (
3 select ename, job
4 from emp
6 order by dbms_random.value()
7 )
8 where rownum <= 5

You might also like