2
DROP TABLE DEPT;
DROP SEQUENCE deptseq;

CREATE TABLE DEPT
(
 DEPTNO             NUMBER(2) NOT NULL,
 DNAME              VARCHAR2(14),
 LOC                VARCHAR2(14),
 CONSTRAINT DEPT_PK PRIMARY KEY (DEPTNO)
);

CREATE SEQUENCE deptseq
INCREMENT BY 10
START WITH 10
NOMAXVALUE
NOCYCLE
NOCACHE;

INSERT INTO DEPT VALUES (deptseq.NEXTVAL,'HR','NY');

This is the SQL I typed into Oracle SQL Developer. However, the first DEPTNO came out with 20. Why is that? I believe this suppose came out with 10.

6
  • A sequence guarantees a non-repeating, monotonically increasing sequence of numbers. It does not guarantee that they will be contiguous. If someone told you there would never, ever be any gaps in your number they lied to you, and you should demand they give you your money back. Jun 15, 2014 at 2:13
  • @BobJarvis This is a duplicate but it's a little more subtle than the typical "why are there gaps?" problem. tldr; Oracle may internally burn the first sequence when deferred segment creation is enabled.
    – Jon Heller
    Jun 15, 2014 at 4:11
  • the question I try to ask is why this is not started with 10? because I run this code before and it works properly. since I wrote START WITH 10 then it should be 10 and 20 - 30 - 40 .... but why this is started with 20 and go 30 - 40 - 50 ...... why 10 is missing? Jun 15, 2014 at 7:37
  • Here's an SQLFiddle showing that the first value obtained from the sequence is 10. Share and enjoy. Jun 15, 2014 at 13:36
  • BTW - is there a trigger which also grabs values from this sequence to populate DEPT.DEPTNO? If there is it would precisely explain this behavior. Jun 15, 2014 at 13:39

1 Answer 1

0

You Just Run the Sequence It's Working

1st Parameter Start With then you can get below output:

CREATE SEQUENCE deptseq

START WITH 10 

INCREMENT BY 10

NOMAXVALUE
NOCYCLE
NOCACHE;

after run above sequence:

select deptseq.nextval from dual;

Output:
=========
10

2
  • This is not an answer since it is just a n exact copy from the question's code. Jun 15, 2014 at 6:32
  • Your updated answer is unclear to me. Jun 15, 2014 at 6:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.