Home » SQL & PL/SQL » SQL & PL/SQL » random numbers (Oracle 11.2.0.3)
random numbers [message #650112] Fri, 15 April 2016 09:27 Go to next message
pointers
Messages: 451
Registered: May 2008
Senior Member
Hi,

can you please help me how to generate random numbers with in list of values.
e.g. I would like to generate random number like 2, 4, 6,8,10,12,14,15,16,20, 200
all the random values should be in the list of above values.

Thank you in advance.

Regards,
Pointers


[EDITED by LF: fixed topic title typo]

[Updated on: Mon, 18 April 2016 01:17] by Moderator

Report message to a moderator

Re: random numners [message #650113 is a reply to message #650112] Fri, 15 April 2016 09:33 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
Use dbms_random.value and then decode its output to your required values.
Re: random numners [message #650114 is a reply to message #650113] Fri, 15 April 2016 09:37 Go to previous messageGo to next message
pointers
Messages: 451
Registered: May 2008
Senior Member
I have around 1000 of different values. How can I use dbms_random to get random values which matches to these 1000 values.

Regards,
Pointers
Re: random numners [message #650115 is a reply to message #650114] Fri, 15 April 2016 09:41 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Put the values in a table along with a row number then do as Roachcoach said to select it.

Re: random numners [message #650131 is a reply to message #650115] Sat, 16 April 2016 13:32 Go to previous messageGo to next message
live4learn
Messages: 41
Registered: September 2013
Location: Bangalore, India
Member
As Michel said ,Put the values in a table . Then just use order by dbms_random.value . can use where rownum < desire_count in the outer query if required.
Re: random numners [message #650132 is a reply to message #650131] Sat, 16 April 2016 13:41 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

No need something so complex, as I said, if you put a row number inside the table along with the desired values then you just have to (equi)join the row number and the value returned by dbms_random.

Previous Topic: sort problem with decimal
Next Topic: Bulk collect data problem
Goto Forum:
  


Current Time: Thu Apr 25 14:51:14 CDT 2024