473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Query taking too long to finish

Hi,

I have two procs which is getting executed one below the other in a package

package1.calc_cl_bal
package1.calc_zone

This is how the procs are defined

Expand|Select|Wrap|Line Numbers
  1. procedure pre_decre_calc_clbal is
  2. c number;
  3. lcnt number(5);
  4. lcnt1 number;
  5. l_msg varchar2(200);
  6. l_mob varchar2(15);
  7. type string_array is table of varchar2(100)index by binary_integer;
  8. type number_array is table of number(13,2) index by binary_integer;
  9.  
  10. clbalm string_array;
  11. clbala number_array;
  12. clbal_tmp number_array;
  13.  
  14. cursor c3 is
  15. select mob from prepaid_sms_bhr_it where name in ('Anantha');
  16.  
  17.  
  18. begin
  19.  
  20. select count(*) into lcnt1 from auto_sh_load where trunc(loaddate)=trunc(sysdate) and filegroup in ('TNSTAT');
  21.  
  22. if lcnt1=1 then
  23.  
  24. select count(*) into lcnt from in_decrement_proc_status where report_date=trunc(sysdate)
  25. and report_name in ('TNCLBAL') and circle='TN';
  26.  
  27. if lcnt=0 then
  28. declare
  29.  
  30. cursor c1 is
  31. select /*+ rule */ mob,nvl(sum(balance),0)
  32. from in_CHE where dum in ('A','G')   group by
  33. mob;
  34. begin
  35. dbms_output.put_line('Closing balance updation started');
  36. open c1;
  37. loop
  38. fetch c1 bulk collect into clbalm,clbala limit 50000;
  39. if clbalm.count >0 then
  40. for i in clbalm.first..clbalm.last loop
  41. clbal_tmp(i) := clbala(i);
  42. end loop;
  43.  
  44. forall ix in clbalm.first..clbalm.last
  45. update in_decrement_base_tn  v set v.clbal=clbal_tmp(ix) where  v.mob=clbalm(ix);
  46. else
  47. exit when c1%notfound;
  48. end if;
  49. end loop;
  50.  
  51. commit;
  52. close c1;
  53. commit;
  54. end;
  55.  
  56.  
  57. insert into in_decrement_proc_status values ('TNCLBAL','COMPLETED',sysdate,trunc(sysdate),'TN','Y');
  58. commit;
  59.  
  60. dbms_output.put_line('Closing balance updation ended');
  61.  
  62. end if;
  63.  
  64. else
  65.  
  66.  
  67.             l_msg:=l_msg||' '||'CLBAL Files not received , TRANS Report will be delayed.';
  68.                 open c3;
  69.                 loop
  70.                     fetch c3 into l_mob;
  71.                     exit when c3%notfound;
  72.  
  73.                         insert into sms(from_num,to_num,msg,sent_flag)
  74.                         select 'SMS',l_mob,l_msg,'N' from dual;
  75.  
  76.                         commit;
  77.  
  78.                         insert into prepaid_decre_sms_log
  79.                         select l_mob,l_msg,sysdate,'N','TN' from dual;
  80.  
  81.                         commit;
  82.  
  83.                 end loop;
  84.  
  85.  
  86.  
  87.  
  88.  
  89. end if;
  90. end;
  91.  
The above proc gets completed in 20 mins or maximum 30 mins. Its mapping 13.8 million records

This the second proc which is very similar to the previous one

Expand|Select|Wrap|Line Numbers
  1. procedure pre_decre_calc_zone is
  2. c number;
  3. lcnt number(5);
  4. lcnt1 number;
  5. l_msg varchar2(200);
  6. l_mob varchar2(15);
  7. type string_array is table of varchar2(200)index by binary_integer;
  8. type number_array is table of number(13,2) index by binary_integer;
  9.  
  10. zonem string_array;
  11. zonea string_array;
  12. zone_tmp string_array;
  13.  
  14.  
  15. cursor c3 is
  16. select mob from prepaid_sms_bhr_itwhere name in ('Anantha');
  17.  
  18.  
  19. begin
  20.  
  21.  
  22. select count(*) into lcnt from in_decrement_proc_status where report_date=trunc(sysdate)
  23. and report_name in ('TNDECREMENT') and circle='TN';
  24.  
  25. if lcnt=1 then
  26.  
  27. select count(*) into lcnt1 from in_decrement_proc_status where report_date=trunc(sysdate) and report_name in ('TNZONE');
  28.  
  29. if lcnt1=0 then
  30.  
  31. declare
  32.  
  33. cursor c1 is
  34. select /*+ rule */ mob,v.zone from cwn_prepaid_zone_mast_new v;
  35.  
  36. begin
  37. dbms_output.put_line('ZONE updation started');
  38. open c1;
  39. loop
  40. fetch c1 bulk collect into zonem,zonea limit 50000;
  41. if zonem.count >0 then
  42. for i in zonem.first..zonem.last loop
  43. zone_tmp(i) := zonea(i);
  44. end loop;
  45.  
  46. forall ix in zonem.first..zonem.last
  47. update in_decrement_base_tn  v set v.zone=zone_tmp(ix) where  v.mob=zonem(ix);
  48. commit;
  49. else
  50. exit when c1%notfound;
  51. end if;
  52. end loop;
  53.  
  54. commit;
  55. close c1;
  56. commit;
  57. end;
  58.  
  59.  
  60. insert into in_decrement_proc_statusvalues ('TNZONE','COMPLETED',sysdate,trunc(sysdate),'TN','Y');
  61. commit;
  62.  
  63. dbms_output.put_line('ZONE updation ended');
  64.  
  65. end if;
  66.  
  67. else
  68.  
  69.  
  70.             l_msg:=l_msg||' '||'ZONE Updation not done, TRANS Report will be delayed.';
  71.                 open c3;
  72.                 loop
  73.                     fetch c3 into l_mob;
  74.                     exit when c3%notfound;
  75.  
  76.                         insert into sms(from_num,to_num,msg,sent_flag)
  77.                         select 'TNDECRESMS',l_mob,l_msg,'N' from dual;
  78.  
  79.                         commit;
  80.  
  81.                         insert into prepaid_decre_sms_log
  82.                         select l_mob,l_msg,sysdate,'N','TN' from dual;
  83.  
  84.                         commit;
  85.  
  86.                 end loop;
  87.  
  88.  
  89.  
  90.  
  91.  
  92. end if;
  93. end;
  94.  
  95.  
  96. end decrement_tn;
  97. /
  98.  
  99.  
This proc also deals with around 13.9 million records but whereas the updation goes for 3 hrs.

I have asked the DBA to rebuild all indexes and also analyze the tables but no performance boost.

Though both the procs are almost identical the time taken for the second one is beyond the scale.

The table in_che and cwn_prepaid_zone_mast_new both contains 13.9 million records.

Note : When i run the procs no other process is running in the server.

Please help in optimizing if possible
Sep 6 '10 #1
0 1529

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Brent | last post by:
Hello all.. I have a recordset that has 12 records in it, and about 25 columns. Unfortunately, I have to write the records out as columns in an ASP page, and the columns as rows. So, what I have done...
3
by: rfuscjr via AccessMonster.com | last post by:
This is truly bizzare. I have a query that runs for hours in one Access db. When I import it into another Access db, it runs in minutes. I compacted and repaired the original, relinked tables...
0
by: eltontodd | last post by:
I have a query that I need to run on a database that is on a SQL Server 7 installation. When I run the query on that database it takes forever. If I take the same query and run it on a database...
0
by: rjy24 | last post by:
Hi, I am facing problem with the following query .It is taking a lot of execution time.I need help with tuning this query. Query: SELECT A, B, C,
3
by: Shal | last post by:
Hi all, I have a table with 300,000 records in it and I want to run an update that has a few clauses in the WHERE command and just changes one boolean value on a subset of records. What I am...
4
by: resmi318 | last post by:
I am running a query similar to given below. CREATE TABLE ABC_08 AS (SELECT x.col1, trim(x.col2), x.col3, x.col4, x.col5 FROM Table1 x
3
by: centeio69 | last post by:
Hello everyone, I'm having some troubles displying this query in SQL Developer.I have 3 tables: MASTER_TRANSACTION_HIST is a big table with millions of rows LOCAL and PLAFOND are small...
0
by: kavin | last post by:
our Customer used to take export backup of a particular schema, previously it used to finish within 30 Minutes. As of now it is taking almost 12 Hours. Export is consuming more time while...
1
by: kavin | last post by:
our Customer used to take backup all the tables of a particular schema using export utility, previously the export operation used to finish within 30 Minutes. As of now it is taking almost 12...
7
by: kiranrajenimbalkar | last post by:
Hi, when i am executing the below SQL its taking long time for execution so please provide me the solution. SELECT A.ID, A.IDTYPE, A.USERNAME, A.FIRSTNAME, ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.