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!

Trying to pull a random number that doesn't exist in a column

520215Aug 28 2007 — edited Aug 28 2007
Hello,

I'm trying to generate a random number that would not exist on a column in PL/SQl on Oracle 8. For example:

Say I have a column (of integers) from 1 to 40. I have records that already exist in this table that has unique values in this column already. so it would look like this

Record_Name | Column_Value
---------------------------------------------------
Test1 | 1
Test2 | 10
Test3 | 27
Test4 | 32
Test5 | 40
Test6 | 2


All unique values......I want to be able to randomly generate a number to put into that column for a new record insert. I know that I can generate a random number by doing this:

trunc(select dbms_random.value (1,40) from dual)

But how can I tell it to not consider what already exists? Any help would be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 25 2007
Added on Aug 28 2007
15 comments
2,427 views