【发布时间】:2020-04-26 18:44:40
【问题描述】:
在存储过程中,我想根据一些条件更新一个大数据集,那么有什么更好的:
场景一(一选多如果)
Select All Data records then
LOOP
IF (Condition1 == true)
execute update statement
IF (Condition2 == true)
execute update statements
END LOOP
场景2(多选where)
Select Data where (condition 1) loop
execute update statements
end loop
Select Data where (condition 2) loop
execute update statements
end loop
【问题讨论】:
-
如果是同一张表,为什么不更新一次呢?如果要更新的行数与表的大小相比很小,那么第一种方法肯定会更糟。如果您可以向我们展示实际的声明,也许我们可以帮助编写一个更新
-
您不应该在一开始就在循环中进行缓慢更新。使用
update ... where condition1和update ... where condition2 -
不可能给出适用于所有可能情况的答案。最接近通用答案的是,在 SELECT 驱动循环中执行单个 DML 语句通常是一种反模式。 SQL 是一种面向集合的语言,因此在集合中做事通常是实现任何目标的最有效方式。
标签: sql oracle performance plsql