日期:2014-05-17  浏览次数:20892 次

大家帮帮忙,oracle中 两个表关联 update的问题
例子:
  a表 字段 id price
  b表 字段 id num
 
我想 把a表中的price update为 a.price*b.num where a.id=b.id
 这个sql语句怎么写?
以前在sql server中写过,但在oracle中 有问题?

------解决方案--------------------
update a
set a.price = (select a.price*b.num from b where a.id = b.id);

试试看~~
------解决方案--------------------
update a 
set a.price = (select a.price*b.num from b where a.id = b.id)
where exists 
(select '1' from b where a.id=b.id); 

------解决方案--------------------
如果B表中id字段是主键,那么还可以写为
update (select a.id,a.price,b.num from a,b where a.id=b.id) set price=price*num