解决方案 »

  1.   

    你自己先把数据导入TB2,然后用一下的存储过程来实现(自己再稍微改动一下)
    create or replace procedure test1 is
      l_count number := 0;
    begin
      for c1 in (select mobile, col1,...sysdate inputtime, source from tb2) loop
        select count(*) into l_count from tgp_funds where fnd_id = c1.fnd_id;
        if l_count > 0 then
          update tgp_funds tb1
             set tb1.col1 = nvl(c1.col1, tb1.col1),
                 tb1.col2 = nvl(c1.col2, tb1.col2),
                 ..       . inputtime = sysdate,
                 source   = source || ',' || c1.source
           where tb1.fnd_id = c1.fnd_id;
        else
          insert into tgp_funds values c1;
        end if;
      end loop;
      commit;
    exception
      when others then
        dbms_output.put_line('Error happened!!');
    end test1;
      

  2.   

    有点改动:
    create or replace procedure test1 is
      l_count number := 0;
    begin
      for c1 in (select mobile, col1,...sysdate inputtime, source from tb2) loop
        select count(*) into l_count from tb1 where mobile = c1.mobile;
        if l_count > 0 then
          update tb1
             set tb1.col1 = nvl(c1.col1, tb1.col1),
                 tb1.col2 = nvl(c1.col2, tb1.col2),
                 ..       . inputtime = sysdate,
                 source   = source || ',' || c1.source
           where tb1.mobile = c1.mobile;
        else
          insert into tb1 values c1;
        end if;
      end loop;
      commit;
    exception
      when others then
        dbms_output.put_line('Error happened!!');
    end test1;
      

  3.   

    等了两天没人回复,今天过来就看到这么一大串代码,惊喜+感动ing,谢谢斑竹!
      

  4.   

    为什么不用merge呢?create or replace procedure test1 is
      l_count number := 0;
    begin
      merge into tb1
      using tb2
      on tb1.mobile = tb2.mobile
      when matched then 
        update set 
          tb1.col1 = nvl(tb2.col1, tb1.col1),
          tb1.col2 = nvl(tb2.col2, tb1.col2),
          ..       . inputtime = sysdate,
          source   = source || ',' || tb2.source
        where tb1.mobile = tb2.mobile
        ;
      when not matched then
        insert (
          mobile,
          col1,
          col2,
          .
          .
          .
         inputtime,
         source
        )
        values(
          mobile,
          col1,
          col2,
          .
          .
          .
         sysdate,
         source
        )
        ;
        commit;
    end;
      

  5.   

    如果我做的话,也是建一个和tb1结构一样的tb2,然后每次都把txt的数据sqlldr进去,补齐缺失字段。存储过程再用merge ,版主的那种写法作为一个懒人第一眼没看懂就没再 看了
      

  6.   

    为什么不用merge呢?create or replace procedure test1 is
      l_count number := 0;
    begin
      merge into tb1
      using tb2
      on tb1.mobile = tb2.mobile
      when matched then 
        update set 
          tb1.col1 = nvl(tb2.col1, tb1.col1),
          tb1.col2 = nvl(tb2.col2, tb1.col2),
          ..       . inputtime = sysdate,
          source   = source || ',' || tb2.source
        where tb1.mobile = tb2.mobile
        ;
      when not matched then
        insert (
          mobile,
          col1,
          col2,
          .
          .
          .
         inputtime,
         source
        )
        values(
          mobile,
          col1,
          col2,
          .
          .
          .
         sysdate,
         source
        )
        ;
        commit;
    end;先谢了!