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

请教一个sql语句。多谢!
我在sql server中有一个如下语句:
Update H Set H.Num = H.Num + A.Num from HSAVE H,
(
  Select MF04, MF09, SUM(MF06) NUM from RKOMF
  WHERE MF01 = 'AA' AND MF02 = 'S001'
  Group by MF04, MF09
) A
Where H.H01 = A.MF04 AND H.H02 = A.MF09

-------------------------------------------------
这个语句我在sql server中是可以正常执行的,可是到oracle中却通不过语法检查,说error第一行, 语句没有正常结束。
请问应该怎么写?

------解决方案--------------------
try:
Update HSAVE H, 

Select MF04, MF09, SUM(MF06) NUM from RKOMF 
WHERE MF01 = 'AA' AND MF02 = 'S001' 
Group by MF04, MF09 
) A Set H.Num = H.Num + A.Num from 
Where H.H01 = A.MF04 AND H.H02 = A.MF09
------解决方案--------------------
oracel里的update只能单表,没有from
------解决方案--------------------
SQL code
Update HSAVE H 
Set H.Num = 
(
  Select  SUM(MF06)+h.num from RKOMF c
  WHERE MF01 = 'AA' AND MF02 = 'S001' 
        and H.H01 = c.MF04 AND H.H02 = c.MF09   
  Group by c.MF04, c.MF09 
)

Where exists(
  Select  1 from RKOMF c
  WHERE MF01 = 'AA' AND MF02 = 'S001' 
        and H.H01 = c.MF04 AND H.H02 = c.MF09   
  )