Oracle sequence:create sequence tc_seq increment by 1 start with 1 nomaxvalue nocycle 注意:start with只能从>=1开始,不能从0开始,超出了范围Oracle trigger:create or replace trigger tc_trg before insert on teacher for each row begin select tc_seq.nextval into :new.id from dual; end; :new含义: new是Oracle的参数,表示新的一行数据,在使用的时候需要在前面加上:,即:new,还有一个参数old,表示旧的 一行数据 for each row:表示行级触发器,每行表记录的操作都会触发,而:new在触发器中使用时,要使用for each row,在行级 触发器中使用。 如果需要两列写法如下: create or replace trigger tc_trg before insert on teacher for each row begin select tc_seq.nextval, tc_seq.nextval into :new.id, :new.age from dual; end; 下面的这种写法是错误的: create or replace trigger tc_trg before insert on teacher for each row begin select tc_seq.nextval into :new.id, tc_seq.nextval into :new.age from dual; end;