是否有一种方法可以仅在另一个字段等于某个值的情况下进行此更新?即。我只想将inv.schedule_finish
设置为inv.nl_sch_chg = 1
。
是SET inv.schedule_finish = CASE WHEN inv.nl_sch_change = 1 THEN ... END CASE;
方面的东西,还是有更好的方法来实现这一点?
这是我目前的声明:
UPDATE INV_INVESTMENTS inv
SET inv.schedule_finish = (SELECT TRUNC(odf.nl_rev_enddate) + 1/(24*60*60)
FROM ODF_CA_CHANGE odf
JOIN RIM_RISKS_AND_ISSUES rim ON rim.ID = odf.ID
WHERE rim.ID = ${gel_objectInstanceId})
WHERE inv.ID = (SELECT rim.PK_ID
FROM RIM_RISKS_AND_ISSUES rim
JOIN INV_INVESTMENTS inv ON inv.ID = rim.PK_ID
JOIN ODF_CA_CHANGE odf ON odf.ID = rim.ID
WHERE odf.ID = ${gel_objectInstanceId});
非常感谢
答案 0 :(得分:0)
您只需将条件添加到where子句中即可:
UPDATE INV_INVESTMENTS inv
SET inv.schedule_finish = (SELECT TRUNC(odf.nl_rev_enddate) + 1/(24*60*60)
FROM ODF_CA_CHANGE odf
JOIN RIM_RISKS_AND_ISSUES rim ON rim.ID = odf.ID
WHERE rim.ID = ${gel_objectInstanceId})
WHERE inv.ID = (SELECT rim.PK_ID
FROM RIM_RISKS_AND_ISSUES rim
JOIN INV_INVESTMENTS inv ON inv.ID = rim.PK_ID
JOIN ODF_CA_CHANGE odf ON odf.ID = rim.ID
WHERE odf.ID = ${gel_objectInstanceId})
AND inv.nl_sch_change = 1
这样,只有带有inv.nl_sch_change = 1
的行将被更新,否则所有行都将被更新,无论数据是否更改。因此,这应该更快一些。
答案 1 :(得分:0)
这是我对您的查询的看法:
现在,找到一种更好的方式来处理此问题。您可以通过两种方式处理此问题: