473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Sequence.nextval incrementing itself over time

My Oracle sequences seem to be auto-incrementing themselves "over time".
My row ID's are sequenced like this:

Expand|Select|Wrap|Line Numbers
  1. 1, 4, 5, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 41, etc
I'm using "sequencename.nextval" when inserting new rows into my tables, so one would think they'd come in a straight sequence?

Example:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO hprequests (requestid, username, flagtype, reqstatus, workstatus, requesttitle, statuschangedby)
  2. VALUES(seqrequestid.nextval, 'username', 'flagtype', 'reqstatus', 'workstatus', 'reqtitle', 'statuschangedby')
  3.  
They seem to be increasing properly when I insert several rows in a row (no pun intended), but if I wait say, a day or two, before inserting another row - it may have been increased by 10 or what not.

I'm using Oracle 9 and OleDB objects in C# to execute the queries.

Have anyone experienced anything like this?
Could it somehow be related to a query failing? Would "execution" of a query increase the value of the sequence despite the failure of the query?
Jul 31 '08 #1
8 11208
r035198x
13,262 8TB
If your id is set to auto increment then why are you providing it in your insert statements? You are trying to increment the id's yourself while the database is also trying to do the same thing for you?
Jul 31 '08 #2
I probably shouldn't have used the word "auto-increment". As far as I know a field can't be set to auto-increment in Oracle (as it can with e.g. MySQL). That's why I need the sequence to increment for me.

I'll try to rephrase myself:
What I ment was that the sequence seems to be incrementing by itself. Even if my application isn't used. So the next time the application is used, and a row is inserted, the sequence does not provide the correct "nextval" but rather a too high value.

I tried to run bad queries from the application on purpose, making them fail, but that didn't provoke the sequence increase either. It seems to be related to time somehow...
Jul 31 '08 #3
r035198x
13,262 8TB
What's your sequence definition like? Do you have a trigger on the table for the sequence?
Jul 31 '08 #4
My sequence was defined like this:

Expand|Select|Wrap|Line Numbers
  1. create sequence SEQREQUESTID
  2. increment by 1
  3. start with 1;
  4.  

I don't have any trigger on the table for the sequence (as far as I'm aware of...?)
I'm not sure I quite followed you on that one?
Did you mean if there is any reference between the sequence and the table, or the ID field? The answer to that would be no. Should there be? Is there some way to tell the ID field to use that particular sequence rather than using seqrequestid.nextval?
Jul 31 '08 #5
I just noticed something rather strange:

It seems to be skipping to "n1" (not without exceptions though...)
So, it has skipped to 21, 41, 61 and 81 so far.
Jul 31 '08 #6
debasisdas
8,127 Expert 4TB
in the sequence defination use the NO CACHE key word.

because if you restart the server all the values in the cache are lost.
Jul 31 '08 #7
Dave44
153 100+
also any failed attempts to insert will lose the grabbed sequence value. all the sequence truly guarentees is a unique value. several conditions can cause "skips" in the numbers.
Aug 1 '08 #8
Debasisdas is on to something. I looked up the no cache thing and found the following which should explain the issue:

When used in a non-cache mode, an access of a sequence which requests
the 'nextval' will increase the current value by the number specified
in the 'increment' section of the sequence and return the new value.
As an example, for a sequence with a current value of zero, an
increment of one, and no cache, the current value would become one,
and one would be returned to the calling statement.


When used with a cache, an access of the sequence which requests the
'nextval' will increase the current value by the increment times the
cache, and will return to the calling function the current value plus
one times the increment. The following access of the nextval *should*
access the cached seqence values and return a number which equals the
previous plus the increment. Ideally, numbers will continue to be
returned from the cache until it has reached the end.


Taken from this article.

As I also needed to display my ID's, I found another way that also seems to have solved the skipping issue. I select the nextval before inserting:

Expand|Select|Wrap|Line Numbers
  1. SELECT seqrequestid.nextval FROM DUAL
I have done some testing on this and I haven't had any skips since I switched to this method.
Thanks for your input everyone!
Aug 4 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: David Stockwell | last post by:
I'm sure this has been asked before, but I wasn't able to find it. First off I know u can't change a tuple but if I wanted to increment a time tuple by one day what is the standard method to do...
3
by: DFS | last post by:
FYI, Using DLookup("ResultsField","Pass-thru query") consumes 2 SEQUENCE numbers each time it's called. Anyone know why?
2
by: dan | last post by:
I have 2 tables, tab1 ( integer incremented sequence , col2, col3 ) and tab2 ( integer from tab1, col4, col5 ). When I call this function to add a record to each table: LOOP select...
2
by: Oscar Tuscon | last post by:
I'm looking at ways to get batches of sequence values s faster. I don't want to set cache or increment to a large number for a variety of reasons. I need to grab id's in batches of varying numbers at...
7
by: urban.widmark | last post by:
Hello We are having some problems with triggers, sequences and union all in V8 on code that worked fine in V7. Was wondering if someone else has seen this and/or knows what to do. A trigger...
0
by: alasdair.johnson | last post by:
A bug I noticed which doesn't seem to be posted on usenet, nor recognized by Oracle (who didn't want to help unless we had been using their ADO.NET provider...): We used to retrieve the sequence...
4
priyan
by: priyan | last post by:
hai everyone, I am having a doubt in inserting data in time field. I am having a table in which in column in timestamp without time zone datatype. I want to insert a row into the table but...
7
by: Rahul B | last post by:
Hi, If i do a "Select nextval for <seq_namefrom sysibm.sysdummy1", it increases the values of nextval by1. How can i find out the nextval of a sequence without actually increasing the value....
7
by: Haneef | last post by:
Hi All The problem is that I need to keep track of time in my program. Getting time using system calls every time I need is definitely very expensive. So one solution could be to spawn a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.