我要执行一项任务,即如果目标表中没有数据,则从源将数据插入目标表中。
过程大约需要45分钟才能完成此任务,是否可以减少时间?下面是示例代码。
procedure sample ( a_in IN varchar2)
IS
v_row number;
v1_row number;
v2_row number;
cursor c1 IS
select a_value, b_value.., from source_table<where condition>;
/* cursor c1 selecting 46 millions record, but inserted few records to the below two destinations tables */
Begin
for i in c1
loop
v_row := 0;
select count(1) into v_row from table_item where item = i.a_value||'_'||a_in;
if v_row > 0 then
select count(1) into v1_row from destination_table1
where item1 = (c1.b_value||'_'||a_in);
if v1_row = 0 then
insert into destination_table1
(a_value, b_value)
values(c1.a_value, c1.b_value);
commit;
end if;
if c1.b_value is not null then
v2_row := 0;
select count(1) into v2_row from destination_table2 where item2 = (c1.a_value ||'_'||a_in) and
item1 = (c1.b_value||'_'||a_in);
if v2_row = 0 then
insert into destination_table2 (item2, item1) values (c1.a_value ||'_'||a_in,
c1.b_value||'_'||a_in);
commit;
end if;
end if;
end if;
end loop;
End sample;
/* this procedure is taking approx. 45mins to complete */