stepehZYH

在oracle中不像mysql可以id自增,所以要通过oracle的触发器实现主键的自增。

1.下面是表结构,原来是没有主键自增的

 

2.将QUESTION_ID设为主键

alter table CHK_T_QUESTION_DTL(表名) add constraint QUESTION_ID(字段) primary key(QUESTION_ID);

3.设值序列化

create sequence SEQ_QUESTION_ID(序列化名)
minvalue 1
maxvalue 99999999
start with 1
increment by 1
cache 50;

4.创建触发器

create or  replace trigger tr_question_dtl(触发器名字)

before insert on CHK_T_QUESTION_DTL(表名)

for each row

begin

select SEQ_QUESTION_ID(序列化名).nextval into :new.QUESTION_ID(自增的字段名) from dual;

end;

下面进行测试

 

分类:

技术点:

相关文章:

  • 2021-09-14
  • 2022-12-23
  • 2021-10-16
  • 2022-03-09
  • 2021-12-22
  • 2022-02-20
猜你喜欢
  • 2021-12-17
  • 2021-12-07
  • 2021-11-01
  • 2021-10-16
  • 2021-11-01
相关资源
相似解决方案