Re: ordering record randomly.

From: Francois Lotter <flotter_at_oldmutual.com>
Date: 15 Nov 2001 22:38:38 -0800
Message-ID: <87531664.0111152238.7cf9e67_at_posting.google.com>


nabanita_chat_at_hotmail.com (Nabanita) wrote in message news:<9811bb34.0111151159.6d86f0db_at_posting.google.com>...
> Can anyone please tell me how to order records from a table in oracle
> randomly?
> I mean, say, there is a table containing user entries. I want a
> recordsset which contains these entries randomly ordered.
> I need this for choosing random winner on fly for sweepstakes..

One way is to write a function returning a random number (see dbms_random package if available to you), and then calling this function:

SELECT A.*,FUNCTION_RETURNING_RANDOM_NUMBER FROM USER_ENTRIES A
ORDER BY FUNCTION_RETURNING_RANDOM_NUMBER; This way might be slow.

Another way is to add a column to your table, say randnum. Populate this column with random rumbers, and order by this column. Now you can index this column for performance.

Regards
Francois Received on Fri Nov 16 2001 - 07:38:38 CET

Original text of this message