Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unique Random number

user12050217Mar 21 2014 — edited Mar 21 2014

Hi,

Oracle 11.2.0.1

Windows

I have a table something like this :

create table rnd (id number,rnd number);

I need a procedure something like this :

exec genrnd(200,300);

So, after executing the procedure there will be 100 rows in the rnd table and there will be unique random numbers in rnd column.  Ok, suppose if I executed again something like this :

exec genrnd(173,514);

so table will be truncated, and (514-173)+1=342 rows will be in rnd table and new unique random numbers will be in rnd column.

Id column is just for purpose of order by.  It will have 1,2,3,....100 or 1,2,3,4,....342 numbers.

I can get random number by this way :

select trunc(dbms_random.value(200,300)) rnd from dual;

select trunc(dbms_random.value(173,514)) rnd from dual;

but thing number should be unique in the given range, so I am not getting how this can be achieved, please help me.

Thanks.

This post has been answered by Nimish Garg on Mar 21 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2014
Added on Mar 21 2014
32 comments
1,157 views