oracle从另一个表更新计算

时间:2016-10-26 22:22:37

标签: sql oracle

UPDATE  a SET a.CRV_AMOUNT = ((b.BASELINE_TOTAL_VALUE * a.CRV_PERCENT) / 100)
 FROM RECAPT.COST_MODEL_DETAIL a, RECAPT.COST_MODEL b
WHERE a.COST_MODEL_ID = b.COST_MODEL_ID;

我在oracle

中没有正确结束SQL命令

2 个答案:

答案 0 :(得分:0)

这不是Oracle语法。另一种方式:

UPDATE RECAPT.COST_MODEL_DETAIL a
    SET CRV_AMOUNT = (SELECT (b.BASELINE_TOTAL_VALUE * a.CRV_PERCENT) / 100
                      FROM RECAPT.COST_MODEL b
                      WHERE a.COST_MODEL_ID = b.COST_MODEL_ID
                     )
    WHERE EXISTS (SELECT 1
                  FROM RECAPT.COST_MODEL b
                  WHERE a.COST_MODEL_ID = b.COST_MODEL_ID
                 );

答案 1 :(得分:0)

每当您根据另一个表中的数据更新表中的数据时,请考虑merge语句而不是updatemerge更灵活,可以在一个语句中用于更新,插入和删除,在某些情况下,它可能比updateinsert更有效。

merge into recapt.cost_model_detail a
  using recapt.cost_model b
  on (a.cost_model_id = b.cost_model_id)
when matched then update
  set a.crv_amount = b.baseline_total_value * a.crv_percent / 100
;