从oracle PL \ SQL中的tableA插入tableB中缺少的行

时间:2014-09-29 15:23:07

标签: sql oracle oracle11g plsqldeveloper

我想在tableB中插入缺少表A的行 当我在oracle上编写下面的代码时,会抛出错误" ORA-00913:值太多了 00913. 00000 - "太多的价值观"

请建议我正确的语法:

insert into tableB 
Select * from 
(Select * 
from tableA A
left join tableB B
on a.id = B.id
and a.year = b.year
where (a.id is null or a.year is null) )A;

1 个答案:

答案 0 :(得分:1)

ISNULL条件需要在tableB的列上,您只需要选择tableA列值。

insert into tableB 
Select * from 
(Select A.* 
from tableA A
left join tableB B
on a.id = B.id
and a.year = b.year
where (b.id is null or b.year is null) )A;