Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issue while inserting in a table using sequence in Oracle 11g Rel 2

894242Oct 13 2011 — edited Oct 14 2011
Hi All,

I am facing issue when I am inserting sequence values in my table.
While inserting, my sequence does not start with the start with value.
Example Script

CREATE SEQUENCE xyz_seq
START WITH 1
INCREMENT BY 1
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOCACHE
NOORDER;

create table abc (an number not null);

insert into abc values (xyz_seq.nextval );

select *
from abc;

drop sequence xyz_seq;

drop table abc;

Output

Sequence created.
Table created.
1 row created.

AN
----------
2
1 row selected.
Sequence dropped.
Table dropped.

I am unable to understand why it is inserting value 2, when my sequence should start at 1.


To overcome this road block, I implemented a different logic.
Example

CREATE SEQUENCE xyz_seq
START WITH 1
INCREMENT BY 1
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOCACHE
NOORDER;

create table abc (an number not null);
declare
x number(1) := xyz_seq.nextval;
begin


insert into abc values (x );
end;
select *
from abc;

drop sequence xyz_seq;

drop table abc;

Output

Sequence created.
Table created.
PL/SQL procedure successfully completed.

AN
----------
1
1 row selected.
Sequence dropped.
Table dropped.

However, my question still remains that why referring to the sequence.nextval in my insert does not return me the start with value.

Regards,
Rishi
This post has been answered by 695836 on Oct 14 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 11 2011
Added on Oct 13 2011
10 comments
2,416 views