Hi, I have a sequence skip number problem.
I have this sequence. The cache is 20 and noorder.
create sequence seq_serial_no minvalue 1 maxvalue 999 start with 2 increment by 1 cycle
The current situation that has arisen is:
I have two servers A and B. They connect to the same database instance.
Sometimes the sequence is incremented, but sometimes it jumps, and every time it jumps, it jumps to the last_number. Here is two examples.
The first example:
server value -- comment
B 201 2025/04/23 9:14
A 202 2025/04/23 9:22
A 221 2025/04/23 10:35 --skip
B 222 2025/04/23 11:08
A 241 2025/04/23 13:22 --skip
B 242 2025/04/23 15:13
A 261 2025/04/23 17:41 --skip
The second examples:
server value -- comment
A 541 2025/05/08 14:36
B 542 2025/05/08 15:12
A 561 2025/05/09 9:28 -- skip
B 562 2025/05/09 10:18
A 563 2025/05/09 10:46
A 581 2025/05/12 9:17 -- skip
B 582 2025/05/12 9:23
A 583 2025/05/12 10:30
B 601 2025/05/12 14:53 -- skip
A 602 2025/05/12 15:19
The skipping of numbers looks like it has something to do with the cache being cleared. May I ask if my guess is correct? If it is right, then what would clear the cache for SGA?
A sequence can
never be guaranteed to not miss a number, independent of whether there is caching or not.
Caching may increase the chances that you might miss some, but there will *always* be gaps in sequences, eg
SQL> create sequence seq nocache;
Sequence created.
SQL> create table t ( x varchar2(5), y int );
Table created.
SQL> insert into t values ('x', seq.nextval);
1 row created.
SQL> insert into t values ('xxxxxxx', seq.nextval);
insert into t values ('xxxxxxx', seq.nextval)
*
ERROR at line 1:
ORA-12899: value too large for column "T"."X" (actual: 7, maximum: 5)
SQL> insert into t values ('x', seq.nextval);
1 row created.
SQL> select * from t;
X Y
----- ----------
x 1
x 3
Bottom line - don't worry about gaps, but some recommended viewing here