sql - 简单更新 (SQL) 与批量更新 (PL/SQL)
问题描述
最近我遇到一个面试问题:在 oracle DB 中更新超过 100 万条记录的表,哪个更好更快,为什么?简单更新:
update employee
set salary = salary + (salary*5%)
where dept_id = l_dept_id
或者
像这样使用批量收集和 forall 语句:`
declare
type t_ntt is table of employee.employee_id%TYPE;
l_ntt t_ntt;
l_dept_id INTEGER := 10;
c_limit INTEGER := 10000;
cursor c is select employee_id from employee where dept_id = l_dept_id;
begin
open c;
loop
fetch c into l_ntt limit c_limit;
exit when l_ntt.count = 0;
forall I in indices of l_ntt
update employee
set salary = salary + (salary*5%)
where employee_id = l_ntt(I);
end loop;
close c;
commit;
end;
`
解决方案
推荐阅读
- jquery - 响应式菜单项 css 不堆叠在一起
- vba - 在变量中分组值?
- python - tuple' 对象没有属性 'get'
- java - 如果单击退出 JDialog,则 JDialog 关闭
- sql - BigQuery中,根据一张表的计算值匹配两张表
- reactjs - 创建用户——React、Firebase 云函数
- php - 如果不是来自主页,PHP Webapge 将无法正常工作
- kubernetes - Kubernetes/Helm:在 Init 和 Main 容器之间共享一个非属性文件
- python - 从 2D 到 1D,如何在混合模型中传递第二个随机效应 [Python, Statsmodel]
- sqlite - 使用 xamarin 表单保存对 sqlite 数据库的更改