oracle 使用触发器实现id自增


前提:存在数据库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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM