有2个表,结构相似,有一个字段关联,现在怎么把A表的数据添加到B表中,条件是A表不在B表的数据?? 请各位高手多多指点,是oracle的数据库

时间:2023-03-09 03:21:27
有2个表,结构相似,有一个字段关联,现在怎么把A表的数据添加到B表中,条件是A表不在B表的数据?? 请各位高手多多指点,是oracle的数据库
1:
insert into b(col1,col2
)select col1,col2 where not exists(select a.col1 from a where a.col1 = b.col1)
2:
INSERT INTO B
(COL1, COL2)
(SELECT COL1, COL2
FROM A
MINUS
SELECT COL1, COL2 FROM B)
3:
使用merge
merge into B
using A on b.col=a.col --关联字段
when not matched then insert values(...,...,...)