我有一个使用for-loop的过程,用于将行从外部表插入到普通表中。该表大约有6-7列。现在我在每个插入上都提交了,这需要大约20分钟来插入4个4mill记录。是否可以在每1k行或每5k行上使用commit进行优化
if mod(i,5000)=0 then
commit;
下面是循环现在的样子:
FOR i IN 1..arr.COUNT
LOOP
begin
INSERT INTO A(...)
values( ...);
commit;
end;
END LOOP;
发布于 2019-02-18 17:38:12
一种方法是使用模函数:
for i in 1 .. arr.count loop
begin
insert into a (...)
values ( ...);
if mod(i, 5000) = 0 then
commit;
end if;
end;
commit;
end loop;
但是,从游标中按块读取数据并使用FORALL
通常要好得多。不过,我不知道使用外部表是否可以做到这一点。
declare
type type_table_of_sometable_rows is table of sometable%rowtype;
v_array type_table_of_sometable_rows;
cursor mycursor is select * from sometable;
begin
open mycursor;
loop
fetch mycursor bulk collect into v_array limit 5000;
exit when v_array.count = 0;
forall i in 1 .. v_array.count
insert into mytable values ( v_array(i).col1, v_array(i).col2) );
commit;
end loop;
end;
发布于 2019-02-19 03:40:07
不如..。
Insert into table
Select * from external_table;
Commit;
发布于 2019-02-18 17:44:36
CURSOR xxx IS
SELECT
*
FROM table t
where t.id='abc';
for Viewxxx in xxx loop
-- Add logic here!
end loop;
https://stackoverflow.com/questions/54743742
复制相似问题