oracle判断insert,mybatis+oracle insert 判断

业务需求:需要在插入数据库之前判断该数据是否已经存在数据库中,如果存在则进行update操作,如果不存在则进行insert操作

使用语句:merge into ser_layout_ccic_person a

using (select '证件号' certificate_code,

'身份类型' certificate_type,

'test' name

from dual) b

on (a.certificate_code = b.certificate_code and a.certificate_type=b.certificate_type)

when matched then

update set a.name = b.name

when not matched then

insert

(a.certificate_code, a.certificate_type, a.name)

values

(b.certificate_code, b.certificate_type, b.name)

mybatis配置:

merge into a

using (select #{certificateCode} certificate_code from dual) b

on (a.certificate_code = b.certificate_code)

when matched then

update set a.name = #{name},

a.sex=#{sex},

a.birthday=#{birthday},

a.native_area_code=#{nativeAreaCode},

a.address=#{address},

a.mobile=#{mobile},

a.used_name=#{usedName}

when not matched then

insert

(a.certificate_code, a.certificate_type, a.name,a.used_name,a.sex,a.birthday,a.native_area_code,a.address,a.mobile,a.type,a.insert_flag)

values

(#{certificateCode},#{certificateType},#{name},#{usedName},#{sex},#{birthday},#{nativeAreaCode},#{address},#{mobile},#{type},#{insertFlag})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值