UPDATE TableA a
   SET a.Name = (select b.NameA FROM TableB B WHERE B.ID = a.ID)
where exists(select 1 from  TableB B WHERE B.ID = a.ID);

解决方案 »

  1.   

    for i in select id,namea from tableb where tableb.id=tablea.id;
     update tablea
        set name=i.namea
      where id=i.id;
      

  2.   

    谢谢二位。
    我用ORARichard(没钱的日子......) 的方法解决了。
    tian00weiwei(weiwei) 的方法很特别,等我测试通过,立刻结分。
      

  3.   

    TO:tian00weiwei(weiwei)
    我创建如下存储过程
    ==========================================================================
    create or replace procedure sp_test123 is
    begin
      for i in select a,b from aa1 where aa1.a = aa2.a
       update aa2
          set b=i.b
        where a=i.a;end sp_test123;出现如下错误信息(for行的最后也测试过有分号的,也有错误,不大一样):
    --------------------------------------------------------------------------Compilation errors for PROCEDURE CICF.SP_TEST123Error: PLS-00103: 出现符号 "SELECT"在需要下列之一时:
            ( - + case mod new null
              <an identifier> <a double-quoted delimited-identifier>
              <a bind variable> reverse avg count current max min prior sql
              stddev sum variance execute forall merge <a SQL statement>
              time timestamp interval date
              <a string literal with character set specification>
              <a number> <a single-quoted SQL string> pipe
           符号 "(" 被替换为 "SELECT" 后继续。
    Line: 3
    Text: for i in select a,b from aa1 where aa1.a = aa2.a;Error: PLS-00103: 出现符号 ";"在需要下列之一时:
            . ( ) * @ % & - + / at for
              mod rem <an exponent (**)> and or group having intersect
              minus order start union where connect ||
    Line: 3
    Text: for i in select a,b from aa1 where aa1.a = aa2.a;Error: PLS-00103: 出现符号 "end-of-file"在需要下列之一时:
            end not pragma
              final instantiable order overriding static member constructor
              map
    Line: 9
    ==========================================================================在SQL Plus中,出现如下信息: 未知的命令开头 "for i in s..." - 忽略了剩余的行。
    ==========================================================================
    我对Oracle不熟悉,请问是什么原因?