Home » SQL & PL/SQL » SQL & PL/SQL » How to generate random numbers from 1 to 100
How to generate random numbers from 1 to 100 [message #14519] Mon, 30 August 2004 03:00 Go to next message
winny
Messages: 2
Registered: August 2004
Junior Member
How can I generate random numbers from 1 to 100 in oracle.

Thanks in advance.
Re: How to generate random numbers from 1 to 100 [message #14520 is a reply to message #14519] Mon, 30 August 2004 03:07 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Use dbms_random.

SQL> SELECT dbms_random.value(0,100) rnd
  2    FROM emp;

      RND
---------
50.742197
9.0046148
21.082742
75.636684
78.810441
65.079245
4.9226177
37.614456
80.375005
28.051462
 65.81851
95.844261
64.904892
67.269404

14 rows selected.

SQL> ed
Wrote file afiedt.buf

  1  SELECT TRUNC(dbms_random.value(0,100)) rnd
  2*   FROM emp
SQL> /

      RND
---------
       55
       83
       49
       17
       81
       84
       30
       89
       76
       49
       29
       75
       22
       22

14 rows selected.

SQL> 
MHE
Re: How to generate random numbers from 1 to 100 [message #14523 is a reply to message #14519] Mon, 30 August 2004 04:38 Go to previous message
Frank Naude
Messages: 4596
Registered: April 1998
Senior Member
Hi,

Here is a SQL example implementing the DBMS_RANDOM package:

SQL> SELECT dbms_random.value(1, 100) FROM DUAL;

DBMS_RANDOM.VALUE(1,100)
------------------------
              18.0949483

SQL> SELECT dbms_random.value(1, 100) FROM DUAL;

DBMS_RANDOM.VALUE(1,100)
------------------------
              56.6432181

SQL> SELECT dbms_random.value(1, 100) FROM DUAL;

DBMS_RANDOM.VALUE(1,100)
------------------------
               42.296391


... and a PL/SQL example:

SQL> SET SERVEROUTPUT ON
SQL> EXEC dbms_output.put_line( dbms_random.value(1, 100) );
52.7678035937852130804385200888381623401

PL/SQL procedure successfully completed.

SQL> EXEC dbms_output.put_line( dbms_random.value(1, 100) );
84.4005053171912713350694725365786760742

PL/SQL procedure successfully completed.

SQL> EXEC dbms_output.put_line( dbms_random.value(1, 100) );
71.64873216807807467722696201098251002315

PL/SQL procedure successfully completed.


Best regards.

Frank
Previous Topic: find out who logged on in particular date
Next Topic: Constraints
Goto Forum:
  


Current Time: Mon Aug 25 14:42:14 CDT 2025