create table t (pk number primary key,name varchar2(20));
create sequence t_seq ;
create trigger t_trigger before insert on t for each row
begin
select seq.nextval into :new.pk from dual;
end;
/
测试:select * from t;
未选定行
SQL> insert into t(name) values ('aa');
已创建 1 行。
SQL> select * from t;
PK NAME
---------- ----------------------------------------
1 aa
SQL> insert into t(name) values ('bb');
已创建 1 行。
SQL> select * from t;
PK NAME
---------- ----------------------------------------
1 aa
2 bb