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!

How to select a random row with for update?

PyrocksNov 7 2010 — edited Nov 8 2010
Hi,

I have a package that needs to assign a random, reusable number (ID) that is not currently being used - to a procedure.
I'm trying to simulate a pool of numbers (IDs) using a table that has an ID and IS_USED columns.

How do I do:
select a random ID (random row) 
from pool_table
where IS_USED is 0 (not taken)
FOR UPDATE
The for update is to lock the row from being taken by another process calling the package.

OR:

Can I simulate a pool of numbers with a different object (not a table)?
I need the numbers to be coherent between sessions (thus package variables will not work) and only one session uses the same ID at any given time. When it finishes the number becomes available for further runs.

Thanks.

Edited by: Pyrocks on Nov 7, 2010 10:45 AM
This post has been answered by Solomon Yakobson on Nov 7 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2010
Added on Nov 7 2010
17 comments
1,556 views