Home  >  Article  >  Database  >  Oracle中使用序列和触发器实现单个字段值自增长

Oracle中使用序列和触发器实现单个字段值自增长

WBOY
WBOYOriginal
2016-06-07 17:15:15926browse

创建序列: create sequence ccxx_ver_seq start with 1 increment by 1; 创建触发器: create or replace trigger ccxx_ver_tri

创建序列:

create sequence ccxx_ver_seq start with 1 increment by 1;

创建触发器:

create or replace trigger ccxx_ver_trig

before insert on ccxx

for each row begin

select ccxx_ver_seq.nextval into :new.version from dual;

end;

ccxx为触发器应用的表名

version为需要进行值自增长的字段名称

测试:

insert into ccxx(ID,XM,SFZH,XS_SZMD_ID) values('aa','aa','aa','aa');

commit;

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn