insert into tableA (col1, col2, col3)
select distinct col1, col2, col3 
from tableB where col1 > 0 
and not exists (select * from tableA
    where col1 = tableB.col1 
    and col2 = tableB.col2)
--這樣应该可以的吧

解决方案 »

  1.   

    上面的在oracle中不能运行吗?出什么错误?
      

  2.   

    如果有错,你可以按如下的步骤来排除
    第一步:
    select * from tableA where col1 = tableB.col1 and col2 = tableB.col2
    第二步:
    select distinct col1, col2, col3 
    from tableB where col1 > 0 
    and not exists (select * from tableA
        where col1 = tableB.col1 
        and col2 = tableB.col2)
    第三步:
    insert into tableA (col1, col2, col3)
    select distinct col1, col2, col3 from tableB where col1 > 0 
    and not exists (select * from tableA
    where tableA.col1 = tableB.col1 
    and tableA.col2 = tableB.col2)