表A 和表B 都只有一个字段,而且是一样的,A中数据'1','2','3','4',B中有'1','3' ,如何让A B同步数据

解决方案 »

  1.   

    --方法1:使用insert...select加minus
    INSERT INTO b
      SELECT col FROM a
      MINUS
      SELECT col FROM b;
      select * from tab;--方法2:使用merge into
    MERGE INTO b
    USING a
    ON (a.col = b.col)
    WHEN NOT MATCHED THEN
      INSERT VALUES (a.col);
      

  2.   

    上面select * from tab;这一行多余
      

  3.   

    --column为你的列名
    insert into b select * from a where a.column not in(select column from b);
      

  4.   

    --用not exists代替not in ,not in无法识别子查询中有NULL的值insert into b select * from a 
    where not exists (select 1 from b where a.col=b.col );
      

  5.   

    西南java技术讨论专区群号:78152089,欢迎加入..