SQL> select * from scott.admin;
ID USERNAME PASSWORD
---------- ---------- ----------
1 admin admin
2 tom tom
SQL> create sequence scott.admin_seq;
序列已创建。
SQL> create or replace trigger scott.admin_id_pk
2 before insert on scott.admin
3 for each row
4 begin
5 select scott.admin_seq.nextval into :new.id from dual;
6 end;
7 /
触发器已创建
SQL> insert into scott.admin(username,password) values('test','test');
已创建 1 行。
SQL> select * from scott.admin;
ID USERNAME PASSWORD
---------- ---------- ----------
1 admin admin
2 tom tom
1 test test
SQL> insert into scott.admin(username,password) values('test','test');
已创建 1 行。
SQL> select * from scott.admin;
ID USERNAME PASSWORD
---------- ---------- ----------
1 admin admin
2 tom tom
1 test test
2 test test
3 test test
4 test test
5 test test
已选择7行。