有2个表 根据t1.a=t2.a 来更新t1.b=t2.b:
update t1 set b=(select t2.b from t2 where t1.a=t2.a);
为什么在from里添加一个t1写成如下语句就会报单行子查询返回多行?
update t1 set b=(select t2.b from t2,t1 where t1.a=t2.a);
为什么添加第3张表也不行:如果要添加第3张表的条件 改怎么写?
update t1 set b=(select t2.b from t2,t3,t1 where t1.a=t2.a and t1.a = t3.a and t2.b=t3.b);
我写成这样为什么会编译不通过?报ORA-00600内部错误代码,参数:[qctVCO:csform],[0],[0],[0],[0],[1],[1],[0]
update t1 set b=(select t2.b from t2 Where t2.b in
 (select t2.b from t2,t3,t1 where t1.a=t2.a and t1.a = t3.a and t2.b=t3.b))
正确的写法是什么啊? 谢谢

解决方案 »

  1.   

    update t1 
    set t1.b=t2.b
    from t1,t2
    where t1.a=t2.a
      

  2.   

    update t1 
    set t1.b=t2.b 
    from t1,t2 
    where t1.a=t2.a
    我不能运行啊
      

  3.   

    update t1
    set b=(select b from t2 where a=t1.a)
    where a=(select a from t2 where a=t1.a);
      

  4.   

    update t1 
    set b=(select b from t2 where a=t1.a)--如果T2有多个a满足a=t1.a,那么就会返回多个b,这时就无法与等号匹配
    where a=(select a from t2 where a=t1.a); 
      

  5.   

    关联语句。。oracle不支持像sql语句
    update a
    set a.val=b.val
    from a,b
    where a.id=b.id
    应该应用
    update a
    set a.val=(select val from b where a.id=b.id)
    where a.id=(select a from b where a.id=b.id)
      

  6.   

    关联语句。。oracle不支持像sql语句
    update a
    set a.val=b.val
    from a,b
    where a.id=b.id
    应该应用
    update a
    set a.val=(select val from b where a.id=b.id)
    where a.id=(select a from b where a.id=b.id)
    或者用
    update()语句