{{{ops$tkyte@8i> create table t ( x int primary key, y int ); Table created.
ops$tkyte@8i> create sequence myseq; Sequence created.
ops$tkyte@8i> create trigger t_trigger
- 2 before insert on t for each row 3 begin 4 if ( :new.x is null ) then 5 select myseq.nextval into :new.x from dual; 6 end if; 7 end; 8 /
Trigger created. }}} I used "if ( :new.x is null ) then..." in order to allow the application to supply a value for the primary key if it desires. You may leave that off -- it would then assign a unique value for EVERY row {{{ops$tkyte@8i> insert into t (x,y) values (-1,2); 1 row created.
ops$tkyte@8i> insert into t (y) values (3); 1 row created.
ops$tkyte@8i> select * from t;
- X Y
- -1 2
- 1 3
ops$tkyte@8i> }}}