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!');

Of course it increases your sequence twice.
After all, you call it twice...

I am new with this oracle.
What do i have to do?

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).

It works now. Thank you very much for help, jwenting.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.