语法:
MERGE INTO [target-table] A USING [source-table sql] B ON([conditional expression] and [...]...)
WHEN MATCHED THEN
[UPDATE sql]
WHEN NOT MATCHED THEN
[INSERT sql]
含义:
判断B表和A表是否满足ON中条件,如果满足则用B表去更新A表,如果不满足,则将B表数据插入A表但是有很多可选项
例子:
-- 可重复执行
alter table table1 nologging;
merge into table1 rc
using
(
select concat(to_char(sysdate,'yyyyMMddHH24mmss'),rownum)id_col,clumn1,clumn2,clumn3,clumn4
from table2
where credit_balance is not null and type<>8 and status = 2 and seq_no is not null)all_record
on (rc.seq_no=all_record.seq_pay_no)
when not matched then
insert /*+ append */
(
RECHARGE_SEQ_NO ,
clumn1 ,
clumn2 ,
clumn3 ,
clumn4 ,
RECHARGE_CHANNEL
)
values(
all_record.id_col,
all_record.clumn1,
all_record.clumn2,
all_record.clumn3,
all_record.clumn4);
commit;
alter table table1 logging;
详见:https://blog.youkuaiyun.com/jeryjeryjery/article/details/70047022