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: Select random number from a list

Re: Select random number from a list

From: Walt <walt_askier_at_SHOESyahoo.com>
Date: Wed, 19 Apr 2006 15:43:17 -0400
Message-ID: <ppw1g.1119$hi2.425@news.itd.umich.edu>


Robert Scheer wrote:

> I have a table that will always have few records. In one of my
> procedures I need to get the values from one of the fields of this
> table, and randomly select one value from this list. This value will be
> used to update a record on another table.
>
> I am using Oracle 10g and read about the DBMS_RANDOM and
> DBMS_RANDOMINTEGER but they can't help me, since I need to select a
> value among a predefined list of values.

Assuming your table of values is called 'foo' and the field you want to select is called 'bar', how about something like this:

Select bar from
(Select rownum rn, bar from foo order by bar) where rn = {use package to get a number between 1 and N

             where N is the number of rows in foo}

If it's in a proc, you can do a rowcount to determine N.

Another approach is to just append a field that contains as values the numbers 1 through N.

//Walt Received on Wed Apr 19 2006 - 14:43:17 CDT

Original text of this message

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