hi guys,
I have a problem with a select and update on a large table (around 1.7 million rows), My table, which is called intersite
looks like this
I have separated the columns by a '|')
INTERSITE TABLE
-------------------------------
calling_site|called_site|no_of_calls|b_2_a_no_of_calls|
A |B |3 |null|
CDF |FT |9 |null|
B |A |1 |null|
FT |CDF |2 |null|
LM |MN |6 |null|
The no_of_calls column depict the calls made from calling_site to called_site (say, A to B). The b_2_a_no_of_calls column at this stage remains null, but it has to be populated with the no_of_calls made from B to A . I have written a procedure for this.
After the procedure is run, this is how the data will look:
calling_site|called_site|no_of_calls|b_2_a_no_of_calls|
A |B |3 |1 |
CDF |FT |9 |2 |
B |A |1 |3 |
FT |CDF |2 |9 |
LM |MN |6 |0 |
My problem is this procedure takes a long time to run (around 20 min), which is not acceptable. How can I make it run faster? I have a composite unique index on (calling_site,called_site).
I have been reading about Bulk Collects and Forall loops, but I have not used these features before, and I am not clear as to how
to fit them in my procedure. Can anyone help?![[ponytails] [ponytails] [ponytails]](/data/assets/smilies/ponytails.gif)
This is what I have done so far:
CREATE OR REPLACE procedure intersite_b_2_a_update
as
cursor c1 is select
calling_site,called_site
from intersite;
v_no_of_calls number;
begin
for calling_site_rec in c1
Loop
begin
select no_of_calls
into v_no_of_calls,
from intersite
where calling_site= calling_site_rec.called_site
and called_site= calling_site_rec.calling_site;
exception when no_data_found then
v_no_of_calls:=0;
end;
update intersite set b_2_a_no_of_calls=v_no_of_calls
where calling_site=calling_site_rec.calling_site
and called_site=calling_site_rec.called_site;
commit;
end loop;
end;
/
I have a problem with a select and update on a large table (around 1.7 million rows), My table, which is called intersite
looks like this
INTERSITE TABLE
-------------------------------
calling_site|called_site|no_of_calls|b_2_a_no_of_calls|
A |B |3 |null|
CDF |FT |9 |null|
B |A |1 |null|
FT |CDF |2 |null|
LM |MN |6 |null|
The no_of_calls column depict the calls made from calling_site to called_site (say, A to B). The b_2_a_no_of_calls column at this stage remains null, but it has to be populated with the no_of_calls made from B to A . I have written a procedure for this.
After the procedure is run, this is how the data will look:
calling_site|called_site|no_of_calls|b_2_a_no_of_calls|
A |B |3 |1 |
CDF |FT |9 |2 |
B |A |1 |3 |
FT |CDF |2 |9 |
LM |MN |6 |0 |
My problem is this procedure takes a long time to run (around 20 min), which is not acceptable. How can I make it run faster? I have a composite unique index on (calling_site,called_site).
I have been reading about Bulk Collects and Forall loops, but I have not used these features before, and I am not clear as to how
to fit them in my procedure. Can anyone help?
![[ponytails] [ponytails] [ponytails]](/data/assets/smilies/ponytails.gif)
This is what I have done so far:
CREATE OR REPLACE procedure intersite_b_2_a_update
as
cursor c1 is select
calling_site,called_site
from intersite;
v_no_of_calls number;
begin
for calling_site_rec in c1
Loop
begin
select no_of_calls
into v_no_of_calls,
from intersite
where calling_site= calling_site_rec.called_site
and called_site= calling_site_rec.calling_site;
exception when no_data_found then
v_no_of_calls:=0;
end;
update intersite set b_2_a_no_of_calls=v_no_of_calls
where calling_site=calling_site_rec.calling_site
and called_site=calling_site_rec.called_site;
commit;
end loop;
end;
/