0
点赞
收藏
分享

微信扫一扫

问题-oracle 自动主键用触发器产生的问题

一叶轻舟okok 2022-02-17 阅读 54

触发器
oracle 触发器的问题:没提交成功也会消耗一个id号;不能在插入成功后才触发。
oracle使用了触发器id自增时,插入语句有id也会被替换掉

insert into table(ID,name) values(123,name);  --123会被触发器使用序列替换了。就是用户不能用自己的值。
这种有什么办法吗

create or replace trigger tri_SM_MESSAGE_RECEIVER_id
  before insert
  on sm_message_receiver 
  for each row
declare
  -- local variables here
begin
  select SEQ_SM_MESSAGE_RECEIVER_ID.nextval into :new.id from dual;  --多个分号不行;
end tri_SM_MESSAGE_RECEIVER_id;
举报

相关推荐

0 条评论