当然可以了
update a set col1=(select col1 from b where a.id=b.id)
 where exists (select 'X' from b where a.id=b.id);

解决方案 »

  1.   

    可以
    update a set col=(select col from b where a.id=b.id)
     where id in (select id from b where a.id=b.id);
      

  2.   

    如果字段名很多怎么办?
    例如字段名是col1,col2,col3等怎么实现呢?
    是不是
    update a set col1,col2,col3=(select col1,col2,col3 from b where a.id=b.id)
     where exists (select 'X' from b where a.id=b.id);
    这样好象不太妥当吧?
    在线等!
      

  3.   

    基本上查不多,加上括号就对了
    update a set (col1,col2,col3)=(select col1,col2,col3 from b where a.id=b.id)
     where exists (select 'X' from b where a.id=b.id);
      

  4.   

    谢谢!
    我试试看,顺便问一下
    那个exists (select 'X' from b where a.id=b.id);中'X'是不是表中的存在的字段名就行了?
      

  5.   

    可以不是,你也可以用别的,例如:
    exists (select 1 from b where a.id=b.id);与
    exists (select 'X' from b where a.id=b.id);等价
      

  6.   

    好象不行呀!ERROR 位于第 1 行:
    ORA-00904: 无效列名???我的列名存在千真万确!我的格式是这样的:
    update a set (col1,col2,col3)=(select col1,col2,col3 from b where b.id1=ss and a.id=b.id)
     where exists (select 'X' from b where a.id=b.id);这里a.id和b.id的id只要是a,b中都有的字段就可以了吧?
    为什么不行呢?
      

  7.   

    应改为:
    update a set (col1,col2,col3)=(select col1,col2,col3 from b where b.id=ss and a.id=b.id) where exists (select 'X' from b where a.id=b.id);
    吧,你写成了b.id1.
      

  8.   

    这个是笔误,实际当然是b.id=ss
    好象在oracle里面没有批量更新,批量删除也是这样吧,条件也是等于别人的ID,所以我准备用循环,一个一个来,不过这样效率就太低了,不知道各位有没有什么办法?
      

  9.   

    我证明bzszp(SongZip) 是对的“无效的列名”:多分几行,就能找到是哪一个了,像这样:放到sqlplus中
    update a set 
    (col1,
    col2,
    col3)=
    (select col1,col2,col3 from b where b.id1=ss and a.id=b.id)
     where exists (select 'X' from b where a.id=b.id);应该是你的字段名写错了