17,082
社区成员
发帖
与我相关
我的任务
分享
merge into game t1 using
(select c_id, c_name from c_table) t2
on (t1.g_id = t2.c_id)
when matched then
update set t1.g_id = t2.c_id, t1.g_name = t2.g_name
where t1.g_id != '1001';
update set t1.g_id = t2.c_id, t1.g_name = t2.g_name
where t1.g_id = '1001';
when not matched then
insert(t1.g_id, t1.g_name) values (t2.c_id, t2.c_name)
where t1.g_id != '1001';
insert(t1.g_id, t1.g_name) values (t2.c_id, t2.c_name)
where t1.g_id = '1001';
-- 试试这个
merge into t1
using t2 on (t1.g_con = t2.c_con)
when matched then
update set t1.g_id = t2.c_id,
t1.g_name = decode(t2.g_id, '1001', t2.c_name, t1.g_name)
when not matched then
insert (g_id, g_name)
values(t2.g_id, decode(t2.g_id, '1001', t2.c_name, default);
如上表,条件f0(t1.g_con = t2.c_con)
条件f0满足,且g_id = 1001时,update set t1.g_id = t2.c_id, t1.g_name = t2.c_name;
条件f0满足,但g_id != 1001时,update set t1.g_id = t2.c_id;
条件f0不满足,但g_id = 1001时,insert(t1.g_id, t1.g_name) values(t2.c_id, t2.c_name);
条件f0不满足,且g_id != 1001时,insert(t1.g_id) values(t2.c_id);
大概,就这么个意思。