Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: can I select a single random row

Re: can I select a single random row

From: John Russell <johnrussell10_at_home.com>
Date: Mon, 07 May 2001 11:11:34 GMT
Message-ID: <tg0dftclk6fpr8sqml9a79pb04popr3hrh@4ax.com>

On Tue, 01 May 2001 17:20:41 GMT, "Baba Yetunde" <nospam_at_nospam.com> wrote:

>Thanks for that chris. I think my initial problem was I did not seed
>DBMS_RANDOM.
>
>Still with this I cannot acheive what I want.
>
>1) What I need to is generate, a set of random numbers based on the amount
>of records in a table.
>2) Take for example table emp, which has ename, dept.
>I want to select the two columns and then add a third column which will be
>populated with the random numbers generated from above based on the number
>of records in the table.
>
>Finally, I would then like to retrieve one row at random.
>
>Is there any easy way of retrieving a single row at random?

You can add the 3rd column as an ascending sequence of integers, then massage the random number into the range 1..COUNT(*) and SELECT ... WHERE COL3 = massaged_random_value.

At work I have the formula to turn the random number into the desired range, and can dig it up if necessary.

John

--
Got an Oracle database question?
Try the search engine for the database docs at:
http://tahiti.oracle.com/
Received on Mon May 07 2001 - 06:11:34 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US