Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Building a random function
Michael S. Post <mpost_at_cftconsulting.com> wrote in message
news:7mlbfv$79p_at_journal.concentric.net...
> I am looking for a random function that I can put into a SQL statement. I
> know such a function does not exist; I'm interested in the best way to make
> it.
> I need to run something like the following:
>
> select field1, field2
> from table1
> order by (field1 - field2) * 100 + random(100)
>
> where random(100) returns a number x where 0 <= x < 100.
> Since the random() function is being called independently each time, how
> does a seed get set properly?
The random function is VIOLATIVE to the RDBMS. You can use it in the SQL statement.
To do this, you should add an addtional column, fill the column with a random value (maybe using a PL/SQL procedure) and order by the column.
By the way, Oracle8 provides a package DBMS_RANDOM, you can use this package to generate random values. Received on Sat Jul 31 1999 - 09:26:35 CDT
![]() |
![]() |