--给你个模版 写个plsql alter tabke tablename nologging; --更新不写入redolog declare v_count number; cursor c1 select ......; begin v_count:=0; for rec in c1 loop update .....; if (v_count>=1000) then commit; v_count:=0; end if; end;
2楼说的很对,批量添加确实速度很快,我测试了一下,插入50万条仅仅用了0.03秒左右,但是批量更新我一直很头疼,批量(不知道是不是)更新了100万条记录竟然用了200多秒。 不过我想,你只有2万条数据,如果对性能不是很严格要求的话,下面的方法应该能满足你的需求,毕竟才2万条记录。 1. 直接使用sql的for循环 for i in (select t,tt from temp_test) loop update test2 set test2.tt = i.tt where test2.t = i.t; end loop; commit; 2.定义一个集合 for i in 1 .. t.count loop update test2 set test2.tt = t(i).tt where t(i).t = test2.t; end loop; commit; 备注:只是个人意见,希望对你有用,也欢迎大家对我指正,提出更佳方案。
forall ....
这个没用过,我的数据是从SQL Server数据库查询出来的,更新到Oracle数据库,所以是先取到数据,然后再去更新。请教一下,使用您提供的方式进行Update,该如何操作。
--给你个模版 写个plsql
alter tabke tablename nologging; --更新不写入redolog declare
v_count number;
cursor c1 select ......;
begin
v_count:=0;
for rec in c1 loop
update .....;
if (v_count>=1000) then
commit;
v_count:=0;
end if;
end;
不过我想,你只有2万条数据,如果对性能不是很严格要求的话,下面的方法应该能满足你的需求,毕竟才2万条记录。
1. 直接使用sql的for循环
for i in (select t,tt from temp_test) loop
update test2 set test2.tt = i.tt where test2.t = i.t;
end loop;
commit;
2.定义一个集合
for i in 1 .. t.count loop
update test2 set test2.tt = t(i).tt where t(i).t = test2.t;
end loop;
commit;
备注:只是个人意见,希望对你有用,也欢迎大家对我指正,提出更佳方案。