Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to select random records?
Use a prime number hashing algorithm to develop a random row number, convert it into a rowid, select where rowid = calculated rowid
You will have to some experimentation to get a good handle on how rowids are built. take a small table and retrieve the rowids and enough other information to tell which rowid applies to which row.
Once you have it scoped out you will can either embed the logic in something that calls Oracle and retrieves each desired row in turn or build a list of desired rowids and then edit the list so that each desired row is called from a shell command, e,g,
"sqlplus scott/tiger select * from table where rowid = '001.134.124';"
Note that this is not the correct length for a rowid, but I wanted to fit the silly thing into one line :-)
Jerry
DBNerd wrote:
>
> Hi,
>
> Is there a way to select certain number records from a table randomly?
> I am doing a survay application that needs to select records from table
> randomly. What I am doing now is to select all records then fetch them
> back and skip records periodically.
> Is there a better way to do it?
>
> Thanks.
> Bob
Received on Sat Sep 27 1997 - 00:00:00 CDT
![]() |
![]() |