前提:存在数据库di_test,主键为id。
1.创建一个索引sequence
create sequence di_test_id 
minvalue 1
nomaxvalue
start with 1
increment by 1
nocache;
2.创建一个触发器。在插入数据之前触发
create or replace trigger trigger_di_test_insert
before insert on di_test
for each row
declare
-- local variable here
begin
-- Column "ID" uses sequence di_test_id
select di_test_id.nextval into :new.ID from dual;
end trigger_di_test_insert;
05-28 23:24