`

orace数据库,多线程,表中新建了唯一约束(多个字段),插入操作时报唯一约束错误,问题处理方法

    博客分类:
  • java
阅读更多
表:
create table SDS_CONFIRM_FOOTBALL_RESULT
(
  ID             NUMBER not null,
  MID            NUMBER not null,
  LID            NUMBER not null,
  LEGNAME        VARCHAR2(200) not null,
  MATCHNAME      VARCHAR2(100) not null
);

alter table SDS_CONFIRM_FOOTBALL_RESULT add constraint UQ_ID unique (MID, LID);



java代码xml中插入语句处理
 insert into SDS_CONFIRM_FOOTBALL_RESULT
     (ID,  MID, LID,  LEGNAME, MATCHNAME)
 select
      111112, 33, 44, '呵呵', 'aa VS bb'
 from dual  where not exists 
    (select 1
         from SDS_CONFIRM_FOOTBALL_RESULT
         where MID = 33 and LID = 44
     )

意思是,如果表中不存在MID = 33 并且 LID = 44的记录,就插入一条 ID = 111112, MID=33, LID=44, LEGNAME= '呵呵', MATCHNAME='aa VS bb' 这样的记录,如果存在就不插入




   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics