Today, I got one problem which is how to set autoincrement value in Oracle. In Microsoft SQL Sever, if you want to set autoincrement in field, check auto increment properties to "true". In Oracle, there is no function. So, we need to create sequence for our existing table and then create trigger for it.

Create a sequence

view plain print about
1create sequence autoincrement_sequence
2start with 1
3increment by 1
4nomaxvalue;

Create a trigger

view plain print about
1create trigger autoincrement_trigger
2before insert on tbl_users
3for each row
4begin
5select autoincrement_sequence.nextval into :new.id from dual;
6end;