17,086
社区成员
发帖
与我相关
我的任务
分享
--MERGE INTO
MERGE INTO TABLEA a --要插入数据的表
using (select sd_cust_pk_seq.nextval seqid,
tb.id i_id,tc.id some_id,mydata selfcolumn
from tableB tb
cross join tableC tc
where tb.column?= '..'
and tc.column?= '..') t --要插入的表
on(t.seqid=a.id)--连接条件
insert
values (t.seqid, t.i_id,t.some_id,t.selfcolumn)
with t as (
select tb.bid, tc.cid, mydata
from tableB tb cross join tableC tc
where tb.column?= '..' and tc.column?= '..'
)
insert into tableA (id, i_id,some_id,selfcolumn)
select sd_cust_pk_seq.nextval, t.* from t
where not exist (select * from tableA
where t.bid=i_id and t.bid=some_id and t.mydata=selfcolumn);
merge into tableA
(id, i_id,some_id,selfcolumn)
USING(select sd_cust_pk_seq.NEXTVAL id1,
tb.id id2,
tc.id id3,
mydata
from tableB tb
cross join tableC tc
where tb.column?= '..'
and tc.column?= '..' ) tableB
ON (tableA.id=tableB.id1 AND tableA.i_id=tableB.id2 AND tableA.some_id=tableB.id3)
WHEN NOT matched THEN
INSERT VALUES(tableB.id1 ,tableB.id2,tableB.id3,tableB.mydata) ;