表1,字段有A,B
表2,字段有A,C
现在需要把C的值update到B中,请求帮助,谢谢
两个表的数据分别在三百万条左右,这个怎么处理?请高手帮助

解决方案 »

  1.   

    update 表1 set b=( select b from 表2 where 表2.A= 表1.A ) where 表1.A in ( select a from 表2 )
      

  2.   


    老大,没有字段C啊,再请教一下,在最后的表1.A in这里是不是应该用"="啊?
      

  3.   

    update 表1 set b=( select c from 表2 where 表2.A= 表1.A and rownum=1) where exists ( select 1  from 表2 where 表1.A =a )
      

  4.   

    update 表1 set b=( select C from 表2 where 表2.A= 表1.A ) where 表1.A in ( select a from 表2 )
       后面用in 因为 select a from 表2 查出来是一个集合,无法用‘=’
      

  5.   


    --再详细点:
    --首先,如果表1有索引的话, 去掉表1中的index
    --然后再做:
    update 表1 set b=( select c from 表2 where 表2.A= 表1.A and rownum=1) 
    where exists ( select 1  from 表2 where 表1.A =a )--最后重建表1的索引
      

  6.   

    update (select s.b a,s2.c c from table1 s,table2 s2 where s.a=s2.a) v set v.c=v.b;
    如果你的两个表的a都是作为主键的话,上面这条语句是最高效的。
      

  7.   

    表1   表2 的A值完全一样的
    alter table tb1 nologging merge into tb1 using tb2 on (tb1.a=tb2.a)
    when matched then
    update set tb1.b=tb2.c
    --or
    update (select tb1.b b,tb2.c c from tb1,tb2 where tb1.a=tb2.a)
    set b=c如果TB1 与tb2的值一样 等同于复制  最好是重新建个与tb1一样的表结构 在采用追加的方式插入
    然后建索引 以及相关的约束
      

  8.   

    merge into tb1 using tb2 on (tb1.a=tb2.a)
    when matched then
    update set tb1.b=tb2.c
    --or
    update (select tb1.b b,tb2.c c from tb1,tb2 where tb1.a=tb2.a)
    set b=c
      

  9.   


    执行merge语句时提示SQL命令未正确结束?
    这个是怎么回事,哪里错了吗?谢谢
      

  10.   


    在PL/SQL中执行这条语句时提示“无法修改与非键值保存表对应的列”,请求帮助,谢谢
      

  11.   

    什么版本的
    把你的sql贴上来
      

  12.   


    数据库是oracle的,我是按照你给的语句格式写的,表名和字段换了
      

  13.   


    alter table new nologging
    merge into new s using new_1 t on (s.p_number=t.p_number)
    when matched then
    update set s.ryhjzzbh=t.zzbh
    --or
    update(select a.ryhjzzbh aa,b.zzbh bb from new a,new_1 b where a.p_number=b.p_number)
    set aa=bb数据库是oracle 10g的,非常感谢啊!!
      

  14.   

    s.p_number=t.p_number 一一对应的
    没问题你的
    merge into new s using new_1 t on (s.p_number=t.p_number)
    when matched then
    update set s.ryhjzzbh=t.zzbh
      

  15.   

    --这个语句不可以?
    merge into new s 
    using new_1 t 
    on (s.p_number=t.p_number)
    when matched then
    update set s.ryhjzzbh=t.zzbh
      

  16.   


    -------测试,A,B表的主键是一样的,都是a
    Connected to Oracle9i Enterprise Edition Release 9.2.0.1.0 
    Connected as EMPLOYE
    SQL> 
    SQL> drop table a;Table droppedSQL> create table A
      2  (
      3     a number primary key,
      4     b varchar2(10)
      5  );Table createdSQL> drop table b;Table droppedSQL> create table B
      2  (
      3     a number primary key,
      4     c varchar2(10)
      5  );Table createdSQL> 
    SQL> insert into a values(1,'aa');1 row insertedSQL> insert into b values(1,'bb');1 row insertedSQL> commit;Commit completeSQL> select * from b;         A C
    ---------- ----------
             1 bbSQL> select * from a;         A B
    ---------- ----------
             1 aaSQL> update (select s.b b,s2.c c from a s,b s2 where s.a=s2.a) v set v.c=v.b;1 row updatedSQL> select * from a;         A B
    ---------- ----------
             1 aaSQL> select * from b;         A C
    ---------- ----------
             1 aaSQL> 
      

  17.   

    实例发给你:update kcdmb set kcdmb.kcywmc=(select kcywmc from A where A.kcdm =kcdmb.kcdm ) where exists(select kcdm from A  where kcdmb.kcdm=A.kcdm)