在oracle中如果要修改a表中一个字段的值,它的值要从b表中一个对应的字段中取
修改语句该怎样写
要根据条件查询
怎么可以更新表中的一列多行记录,并且每行的记录不同

解决方案 »

  1.   

    update a set a.col = (select b.col from b where a.id = b.id)
    where exists (select 1 from b where a.id = b.id)
      

  2.   

    最好加上max或者min,防止 返回多行 的错误。
    update a set a.col = (select max(b.col) from b where a.id = b.id)
    where exists (select 1 from b where a.id = b.id)
      

  3.   

    exists语句,如果又返回值,则 更新 ,返回什么值 无所谓
    select * from b where a.id = b.id

    select col from b where a.id = b.id
    都一样的效果。