Solved

Sequence out of order

Posted on 2004-08-20
5
1,134 Views
Last Modified: 2008-01-09
Hi to all,

I am having problems with a sequence so my question is:

Considering that the instance have been up and running, is it possible for a sequence to give a wrong number?  (minor than the current)

in case that YES, why?

Please notice that this have never occurred to me in the past, so I am looking for bugs or anything that can cause this behavior.

I am still working in cheking the developer code.-

Thanks to all.-

0
Comment
Question by:fadeshadow
5 Comments
 
LVL 23

Assisted Solution

by:seazodiac
seazodiac earned 62 total points
ID: 11856368
if you mean Oracle sequence object,
I would say almost never, though there is one exception I can think of

if you are defining sequence with CYCLE and MAXVALUE,

that means once sequence has reach the maxvalue, it will turn around to start with the minvalue.
0
 
LVL 4

Accepted Solution

by:
andertst earned 64 total points
ID: 11856786
Also, if the application grabs a seq# for a user and does not immediately insert into the db, another user comes along and gets the next higher number, then if the second user saves the record firs, the first user could save the record later with a smaller seq#.

This shouldn't cause any problems unless the application defines a sequence number as the sequence the records were actually saved.

Stephen
0
 
LVL 6

Assisted Solution

by:morphman
morphman earned 62 total points
ID: 11858787
Check that the code doesnt use anything BUT seq.nextval (ie no references to seq.nextval + 1 or any assumed logic like that)

0
 
LVL 9

Assisted Solution

by:pratikroy
pratikroy earned 62 total points
ID: 11869139
There are times, when the NEXTVAL is fetched multiple times, but records are inserted only once. So there are gaps in the sequence (that you might notice - in terms of the column values(PK) in a table). But actually SEQUENCE would have generated numbers in correct order.

There could be a time when instead of fetching the NEXTVAL, one has selected the CURRVAL from the sequence. This could give some error, or the number that was fetched by previous fetch of NEXTVAL.

If you get a number that was generated before, it could be possible if there was a CYCLE and MAXVALUE parameters provided at the time of creation of sequence (or by an ALTER statement). You would typically be ready to get the same number (if you chose to have these in your SEQUENCE), because it is meant to start from the first number, once the MAX value has reached.

If the sequence has been generated by the program, then there is a possibility of a bug in the code that is generating the sequence. Typically, developers fetch the last record (MAX PK) from the table, and add one to it, to get the next value of the sequence number. But there might be issues related to integrity and consistency in this.

Hope this helps !

0
 
LVL 1

Author Comment

by:fadeshadow
ID: 11869769
Well,

As you guys said, it is very rare for a sequence to get out of order, now, after some research, we found that some developer did some "hidden" operations.

I will try to split point along your answers,

Thanks to all for your support.

Carlos Acosta Alamo
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now