create table a
(
a1 int ,
a2 varchar2(6)
);
create SEQUENCE seq_a INCREMENT BY 1; -- 創建一個序列
create or replace TRIGGER a_insert -- 創建一個before insert的觸發器在表a上
before insert on a
for each row
declare
i_id integer;
begin
select seq_a.nextval into i_id from dual; --seq_a.nextval是該序列的下個值
:NEW.a1 := i_id;
end;
然後在insert時:
insert into a(a2) values('hello!'); -- 不對a1進行處理,觸發器會自動幫你處理