0

Hi,
Below trigger increments double(2,4,6,8...) not single. I want single. Where is mistake? If you can not help, is there other way to do auto increment?
Thanks

CREATE TABLE MY_TEST
(
  IDNUM NUMBER,
  NAME VARCHAR2(4000)
)
;

create sequence test_seq 
start with 1 
increment by 1 
nomaxvalue;  


create trigger test_trigger
before insert on MY_TEST
for each row
begin
select test_seq.nextval into :new.idnum from dual;
end; 


insert into my_test values(test_seq.nextval, 'voila!');
2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by veledrom
0

Don't call the sequence in the insert statement.
Instead use

insert into my_test (name) values ('Voila!');

The trigger will call the sequence, and fill in the ID.

You should best change the name of that column though. Best practice is to never use things that could be reserved words in some programming language (and especially SQL).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.