这个意思?select b.owner, b.object_name from b where not exists (select 1 from a where b.object_id = a.object_id);
这个意思?select b.owner, b.object_name from b where not exists (select 1 from a where b.object_id = a.object_id); 不对,拷贝错SQL了 应该是这个: insert into b select a.* from a where not exists (select 1 from b where b.id = a.id)
如果还有判断已经有是否重复,有了就更新,没有就插入 建议使用 类似 merge into hwicd.t_handle_reply_info a using t_tmp_handle_reply_info b on (a.handleid = b.handleid) WHEN MATCHED THEN UPDATE SET a.updatetime=b.updatetime, a.handleopinion =b.handleopinion WHEN NOT MATCHED THEN insert ( a.handleid, a.orderid, a.inchargedept, a.handleper, a.handleopinion, a.handledate, a.state, a.statetime, a.createtime, a.updatetime) VALUES (b.handleid, b.orderid, b.inchargedept, b.handleper, b.handleopinion, b.handledate, b.state, b.statetime, b.createtime, b.updatetime);
insert into tb1 select tb2.* from tb2 where tb2.id not in (select id from tb1 )
题目的方式和思路有待大大加强啊。我这里假设表为test,主键字段为id,insert来源表为tmpinsert into test
select *
from tmp a
left join test b on b.id = a.id
where b.id is null
这个意思?select b.owner, b.object_name
from b
where not exists (select 1 from a where b.object_id = a.object_id);
这个意思?select b.owner, b.object_name
from b
where not exists (select 1 from a where b.object_id = a.object_id);
不对,拷贝错SQL了 应该是这个:
insert into b
select a.*
from a
where not exists (select 1 from b where b.id = a.id)
https://www.cnblogs.com/dongsheng/p/4384754.htmlmerge...into 执行前先判断一下
https://www.cnblogs.com/dongsheng/p/4384754.html
merge...into 执行前先判断一下
建议使用 类似
merge into hwicd.t_handle_reply_info a
using t_tmp_handle_reply_info b
on (a.handleid = b.handleid)
WHEN MATCHED THEN
UPDATE SET a.updatetime=b.updatetime,
a.handleopinion =b.handleopinion
WHEN NOT MATCHED THEN
insert ( a.handleid,
a.orderid,
a.inchargedept,
a.handleper,
a.handleopinion,
a.handledate,
a.state,
a.statetime,
a.createtime,
a.updatetime)
VALUES (b.handleid,
b.orderid,
b.inchargedept,
b.handleper,
b.handleopinion,
b.handledate,
b.state,
b.statetime,
b.createtime,
b.updatetime);
insert into tb1 select tb2.* from tb2
where tb2.id not in (select id from tb1 )