【ORACLE】MERGE

MERGE INTO KM18_SJCONTROL K
USINGSELECT 
 :HIN_SYBASYO_CD AS HIN_SYBASYO_CD
,:SYUKA_SEND_DATE AS SYUKA_SEND_DATE
,:SYUKA_SEND_TIME AS SYUKA_SEND_TIME
,:SYUKA_SEND_PC AS SYUKA_SEND_PC
,:SYORI_FLG AS SYORI_FLG
,:MK_DATE AS MK_DATE
,:MK_TIME AS MK_TIME
,:UP_DATE AS UP_DATE
,:UP_TIME AS UP_TIME
 FROM DUAL
 ) D
ON (K.HIN_SYBASYO_CD=D.HIN_SYBASYO_CD)

WHEN MATCHED THEN UPDATE
SET 
 SYUKA_SEND_DATE=D.SYUKA_SEND_DATE
,SYUKA_SEND_TIME=D.SYUKA_SEND_TIME
,SYUKA_SEND_PC=D.SYUKA_SEND_PC
,SYORI_FLG=D.SYORI_FLG
,MK_DATE=D.MK_DATE
,MK_TIME=D.MK_TIME
,UP_DATE=D.UP_DATE
,UP_TIME=D.UP_TIME

WHEN NOT MATCHED THEN INSERT ( 
 HIN_SYBASYO_CD
,SYUKA_SEND_DATE
,SYUKA_SEND_TIME
,SYUKA_SEND_PC
,SYORI_FLG
,MK_DATE
,MK_TIME
,UP_DATE
,UP_TIME)
VALUES (
 D.HIN_SYBASYO_CD
,D.SYUKA_SEND_DATE
,D.SYUKA_SEND_TIME
,D.SYUKA_SEND_PC
,D.SYORI_FLG
,D.MK_DATE
,D.MK_TIME
,D.UP_DATE
,D.UP_TIME
)

一条完整的merge语句,在按照原有的数据更新的时候(并不知道有没有这条数据存在),用merge语句可以解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值