Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sequence out of order

Posted on 2004-08-20
5
Medium Priority
?
1,191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Assisted Solution

by:seazodiac
seazodiac earned 248 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 256 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 248 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 248 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

722 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