MERGE INTO 的使用

MERGE INTO  RPT_EVENT_TRANMON_HIS t5   
Using  (select t1.REM_ID, t1.EVENT_ID, t1.MERCHANT_CODE, t1.LIQ_DATE, t1.REM_AMT, t1.REM_ACCT,
t2.CREATE_TIME    FROM WF_EVENT_TRANMON t1 ,WF_EVENT_SHEET t2   where  t1.EVENT_ID=t2.EVENT_ID and t2.LAST_UPDATE_TIME 
 between :bizBeginDate and :bizEndDate) t4
ON (t5.REM_ID=t4.REM_ID AND t5.EVENT_ID=t4.EVENT_ID)
WHEN MATCHED THEN 
update set  
t5.MERCHANT_CODE=t4.MERCHANT_CODE, t5.LIQ_DATE=t4.LIQ_DATE,
t5.REM_AMT=t4.REM_AMT, t5.REM_ACCT=t4.REM_ACCT, t5.CREATE_TIME=t4.CREATE_TIME
WHEN NOT MATCHED THEN 
insert 
(t5.REM_ID, t5.EVENT_ID, t5.MERCHANT_CODE, t5.LIQ_DATE, t5.REM_AMT, 
t5.REM_ACCT, t5.CREATE_TIME)
values
(t4.REM_ID, t4.EVENT_ID, t4.MERCHANT_CODE, t4.LIQ_DATE, t4.REM_AMT, 
t4.REM_ACCT, t4.CREATE_TIME)    

你可能感兴趣的:(原创)