Solved

Sequence out of order

Posted on 2004-08-20
5
1,186 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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 copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Suggested Courses

632 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