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!

Recycled Sequence Numbers

User9954330-OracleMay 7 2012 — edited May 7 2012
Hi,
We have a requirement of generating sequence numbers for a table and we need to recycle them if some of them is deleted.

For example the following tabe Employee(Id,name)

ID NAME
1 XXX
2 YYY
3 ZZZ
4 AAA

The ID filed should have the next sequence number generated. When I call getnextID now, it should return 5
ID NAME
1 XXX
2 YYY
3 ZZZ
4 AAA
5 BBB

Now Let us assume I delete 3. The contents of the table aare

ID NAME
1 XXX
2 YYY
4 AAA
5 BBB

Now when getNextID, 3 should be returned.
How to achieve this in a best performing way in Oracle? Are there any patterns around it? Please note this should run in a multi user environment.

Thanks,
Rama
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2012
Added on May 7 2012
11 comments
680 views