update t1 set a= t2.x
from t1,t2
where t1.b=t2.b and t2.c= 44这样的sqlserver语句如何在oracel中写?update t1 set a=  (select x from t2 where t1.b=b and c=44) 这样写法为何不对?

解决方案 »

  1.   

    可以,不过这样写好些,先过滤,速度会快些
    update t1 set a=(select   max(x)   from   t2   where   t1.b=b)
    where a.b in (select t2.b from t2 where t2.c=44)
      

  2.   

    update emp t1 set ename=(select ename  from emp t2 where t1.empno=t2.empno and t2.empno=10)
      

  3.   

    以上几个sql是否忽略了一个问题:
    如果子查询返回的结果多于一条记录,那更新语句将会出错?如果不能保证结果只是一条记录,那是不是还要套一个子查询和rownum来保证只有一条记录?
      

  4.   

    提示:无法将 NULL 值插入列,...............这样写法不对的
      

  5.   

    能不能当两表数据相匹配时,进行更新,当前子查询没有查到时不更新,像sqlserver 
    update   t1   set   a=   t2.x 
    from   t1,t2 
    where   t1.b=t2.b   and   t2.c=   44 
      

  6.   

    select   x   from   t2   where   t1.b=b   and   c=44
    这句不对
    这个语句里没有T1表,WHERE里怎么会对
      

  7.   

    能不能当两表数据相匹配时,进行更新,当前子查询没有查到时不更新,像sqlserver   
    update       t1       set       a=       t2.x   
    from       t1,t2   
    where       t1.b=t2.b       and       t2.c=       44   
      

  8.   


    update t1 T
       set a = (select S.x
                  from t2 S
                 where T.b = S.b
                   and S.c = '44')
     where exists (select 1
              from t2 S
             where T.b = S.b
               and S.c = '44')菜鸟也来凑下热闹 
      

  9.   

    顶上面的
    update   t1   T
          set   a   =   (select distinct   S.x
                                from   t2   S
                              where   T.b   =   S.b
                                  and   S.c   =   '44')
      where   exists   (select   1
                        from   t2   S
                      where   T.b   =   S.b
                          and   S.c   =   '44') 
    加个distinct,防止返回多条记录除此之外还有没有别的方法了,
    如果要更新一个以上的字段,这个方法好像就不好使了...请高人指点
    关注中......