Oracle Autoincrement Column On Insert
MySQL has a nice little autoincrement attribute that will allow you to increment a column value on insert. Oracle does not have this, but there is a workaround:
Here is an example:
1.
create table mytable (id number, xyz varchar2(255));
2.
create sequence mytable_seq start with 1 increment by 1 nomaxvalue;
3.
create trigger mytable_trigger
before insert on mytable
for each row
begin
select mytable_seq.nextval into :new.id from dual;
end;
/
Advertisement
Leave a Comment