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!

Sequence with multiple increments

Peter MarcoenNov 21 2012 — edited Nov 22 2012
In our database we have a sequence that is used by 2 different applications.

Application A requests *1000* ids, that it will use.
Application B requests *100* ids.

One possible solution could be the following:

The sequence is created with increment *1*.
The application requests the nextval.
The application drops the sequence.
The application recreates the sequence with the value it got + 100/1000.

The problem here is that these applications consist of multiple threads. When thread 1 drops the sequence and thread 2 requests the nextval, the application will fail.

Another solution could be the following:

The sequence is created with increment *1*.
The application requests the nextval.
The application increments the sequence with 100/1000.

Here I am a bit worried about thread 2 requesting the nextval after thread 1 requested the nextval but before thread 1 incremented the sequence.
Maybe if executed as 1 transaction, this problem will not occur?

I would really like to hear your thoughts on this.
This post has been answered by Nicosa-Oracle on Nov 21 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2012
Added on Nov 21 2012
59 comments
5,473 views