merge into
table_a a
using
table_b b
on(a.id=b.id)
when
not matched
then
insert(a.id,a.col,a.col2.....) values(b.id,b.col,b.col2.......)
列子:(mybatis中的xml)
入参:对象
表b根据入参创建,然后判断表b跟表a的主键是否冲突,不冲突则插入
merge into
attence_temp_work a
using
(select
#{custMemberId,jdbcType=CHAR} CUST_MEMBER_ID,
#{date,jdbcType=CHAR} "DATE",
#{custId,jdbcType=CHAR} CUST_ID,
#{workTimeId,jdbcType=INTEGER} WORK_TIME_ID,
#{workNature,jdbcType=CHAR} WORK_NATURE,
#{overWorkFlag,jdbcType=CHAR} OVER_WORK_FLAG,
#{overWorkTime,jdbcType=INTEGER} OVER_WORK_TIME,
#{createdOperCode,jdbcType=CHAR} CREATED_OPER_CODE,
#{createdStamp,jdbcType=TIMESTAMP} CREATED_STAMP,
#{lastUpdatedStamp,jdbcType=TIMESTAMP} LAST_UPDATED_STAMP,
#{lastUpdatedOperCode,jdbcType=CHAR} LAST_UPDATED_OPER_CODE,
#{workAroundId,jdbcType=INTEGER} WORK_AROUND_ID
from dual
) b
on(a.CUST_MEMBER_ID=b.CUST_MEMBER_ID and a."DATE"=b."DATE")
when not matched
then
insert
a.cust_member_id,
a."DATE",
a.cust_id,
a.work_time_id,
a.work_nature,
a.over_work_flag,
a.over_work_time,
a.created_oper_code,
a.created_stamp,
a.last_updated_stamp,
a.last_updated_oper_code,
a.work_around_id,
#{custMemberId,jdbcType=CHAR},
#{date,jdbcType=CHAR},
#{custId,jdbcType=CHAR},
#{workTimeId,jdbcType=INTEGER},
#{workNature,jdbcType=CHAR},
#{overWorkFlag,jdbcType=CHAR},
#{overWorkTime,jdbcType=INTEGER},
#{createdOperCode,jdbcType=CHAR},
#{createdStamp,jdbcType=TIMESTAMP},
#{lastUpdatedStamp,jdbcType=TIMESTAMP},
#{lastUpdatedOperCode,jdbcType=CHAR},
#{workAroundId,jdbcType=INTEGER},