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命令答案 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
语句而不是update
。 merge
更灵活,可以在一个语句中用于更新,插入和删除,在某些情况下,它可能比update
或insert
更有效。
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
;