Solved

Sequence out of order

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
history tablespace temp usage 2 38
Oracle SQL 6 57
1 FROM DUAL wont work with additional columns ?? 4 36
PL/SQL More than one element associated with another element 7 25
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

813 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

15 Experts available now in Live!

Get 1:1 Help Now