Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequence increment by 50 instead of 1

I created an Oracle sequence:

Create sequence seq_acteurs start with 1 increment by 1;

Normally the sequence must be incremented by 1, but when insert into Acteurs table, the sequence s incremented by 50! That doesn't seem logical. Why is this so?

Any help will much apreciated.

like image 520
cascadox Avatar asked May 29 '11 18:05

cascadox


People also ask

What is increment by in sequence?

INCREMENT BY Specify the interval between sequence numbers. This integer value can be any positive or negative integer, but it cannot be 0. This value can have 28 or fewer digits. The absolute of this value must be less than the difference of MAXVALUE and MINVALUE .

Can we decrement a sequence value?

To decrement sequence, set the value for INCREMENT BY to a negative number. Setting INCREMENT BY to -1 decrements the sequence object by 1.

What is the maximum value for Oracle sequence?

Specifies the largest value the sequence number can reach. The default is NOMAXVALUE, which means the maximum value is 10 27.

What is Cache value in sequence?

CACHE. Specify how many values of the sequence the database preallocates and keeps in memory for faster access. This integer value can have 28 or fewer digits. The minimum value for this parameter is 2. For sequences that cycle, this value must be less than the number of values in the cycle.


2 Answers

Sequence numbers are not fetched one at a time when you need them. NOrmally, the DB caches a certain number of sequence numbers in memory. WHen the cached sequences are all used up, then the DB fetches a new block of sequence numbers into cache. Now if the DB crashes for some reason while the cache still has some unused numbers, then there could be some gaps in your sequence numbers.

like image 119
Basanth Roy Avatar answered Nov 21 '22 10:11

Basanth Roy


Sequences does not guarantee that they generate a gap free sequence of numbers.

You can minimize the gaps by specifying nocache, but this does still not guarantee gap free sequences, and might create a resource contention.

Example from the documentation:

CREATE SEQUENCE customers_seq START WITH 1000 INCREMENT BY 1 NOCACHE NOCYCLE;

like image 33
oluies Avatar answered Nov 21 '22 08:11

oluies