KG1973
asked on
How to create random number using oracle ?
I want to create a random number between 1 to n and return any number within the range using sql. Our database is oracle 10g.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
with the below code, i am able to generate 10 random numbers between 1 and 10
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
l_seed BINARY_INTEGER;
BEGIN
l_seed := TO_NUMBER(TO_CHAR(SYSDATE, 'YYYYDDMMS S'));
DBMS_RANDOM.initialize (val => l_seed);
FOR cur_rec IN 1 ..10 LOOP
DBMS_OUTPUT.put_line('valu e(low => 1, high => 10): ' || round(to_number(TO_CHAR(DB MS_RANDOM. value(low => 1, high => 10)))));
END LOOP;
DBMS_RANDOM.terminate;
END;
/
Thanks
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
l_seed BINARY_INTEGER;
BEGIN
l_seed := TO_NUMBER(TO_CHAR(SYSDATE,
DBMS_RANDOM.initialize (val => l_seed);
FOR cur_rec IN 1 ..10 LOOP
DBMS_OUTPUT.put_line('valu
END LOOP;
DBMS_RANDOM.terminate;
END;
/
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect solution.
ASKER
You just solved my problem. Thank you very much.
http://www.oracle-base.com/articles/9i/UsefulProceduresAndFunctions9i.php
Refer to the 2nd above url. which contains good examples on how to generate random numbers.