Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1205
  • Last Modified:

Sequence out of order

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
fadeshadow
Asked:
fadeshadow
4 Solutions
 
seazodiacCommented:
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
 
andertstCommented:
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
 
morphmanCommented:
Check that the code doesnt use anything BUT seq.nextval (ie no references to seq.nextval + 1 or any assumed logic like that)

0
 
pratikroyCommented:
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
 
fadeshadowAuthor Commented:
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now