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: random records

Re: random records

From: Charles Hooper <hooperc2000_at_yahoo.com>
Date: 12 Jul 2006 07:58:45 -0700
Message-ID: <1152716325.075325.28460@m79g2000cwm.googlegroups.com>


Faby wrote:
> Thank you Charles.
> May I ask you one more question. How does dbms_random works? I'm still
> a bit confused
> Thanks

Execute this SQL statement 10 times:
SELECT
  DBMS_RANDOM.VALUE
FROM
  DUAL; DBMS_RANDOM generates pseudo random floating point numbers greater than or equal to 0 and less than 1.

Generates pseudo random integer values between 1 and 100 SELECT
  TRUNC(DBMS_RANDOM.VALUE*100)+1
FROM
  DUAL; Looking at Tom Kyte's example:
SELECT
  *
FROM
  (SELECT
    EMPNO,
    ENAME
  FROM
    EMP
  WHERE
    ENAME LIKE '%'
  ORDER BY
    DBMS_RANDOM.VALUE)
  WHERE
    ROWNUM <= 4;

He selects the records in an inline view and sorts them by randomly generated values between 0 and .99999999. Once this is done, the rows come out of the inline view with a new ROWNUM value. ROWNUM <= 4 only retrieves the first 4 rows of from the inline view.

I don't use DBMS_RANDOM much, but it looks like this approach may be helpful on occasion.

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc. Received on Wed Jul 12 2006 - 09:58:45 CDT

Original text of this message

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