【发布时间】:2022-02-07 20:08:46
【问题描述】:
我有这个问题:
update rexcms e
set e.cocnd=(select r.cocnd
from rexcms r
where NVL(r.marche,'*')=NVL(e.marche,'*')
and r.cocrd= e.cocrd
and r.cocol=e.cocol
and r.cocol='CHBIL'
and r.marche='CBOT')
where e.cocol ='CDVHB' ;
如何使用 EXISTS 来优化它
【问题讨论】:
-
您似乎对
EXISTS是什么有误解。EXISTS不是优化查询的工具。它旨在将查找条件添加到查询中。因此,如果您将EXISTS放入更新语句中,您不会对其进行增强,而是对其进行更改(通过将更新的行限制为存在的行)。 -
究竟如何使用 exixts 编写查询,您能帮我吗? PLZ
-
你还是不明白。
EXISTS更改您的查询。如果您只想更新表 abc 中存在 cocnd 的行,则添加and exists (select null from abc where abc.cocnd = e.cocnd),但如果您只想更新 Marches 表中存在 marche 的行,则添加and exists (select null from marches where marches.marche = e.marche)。我怎么知道您想以哪种方式更改查询的功能?我无法读心。 -
我现在取消了正确的查询,谢谢 :)
标签: sql oracle optimization sql-update exists