RE: PL/SQL question





Is it possible for all detail tables be updated without using a cursor.
can u explain with example.




                                                                                
                                                       
                      "Kennedy, Jim"                                            
                                                       
                      <jim_kennedy@men         To:      
<manoj.gurnani@xxxxxxxxxxxxx>, <oracle-l@xxxxxxxxxxxxx>                        
                      tor.com>                 cc:                              
                                                       
                                               Subject: RE: PL/SQL question     
                                                       
                      09/28/2005 07:02                                          
                                                       
                      PM                                                        
                                                       
                                                                                
                                                       
                                                                                
                                                       







I don't see why you are using execute immediate.  I think you could do it
all in one sql statement.  To quote Mr. Kyte "Row by row is slow by slow".
I think you have over complicated it.
Jim

-----Original Message-----
From: oracle-l-bounce@xxxxxxxxxxxxx on behalf of
manoj.gurnani@xxxxxxxxxxxxx
Sent: Wed 9/28/2005 6:28 AM
To: oracle-l@xxxxxxxxxxxxx
Subject: Re: PL/SQL question






Below is the code.
the cursor has about 300000 recs.
The details tables have large volume of data  and some have about 30 recs
for each ref_num in cursor.
This script has to be run .Can performance be increased.
I've tested this for 3000 recs in cursor and with lesser volume of data in
detail table.
time taken is 25 min.
Note :index is not present in all detail tables on column used in filter.


set timing on
set serverout on size 1000000
declare
l_commit_interval number := 5000;
l_where_clause varchar2(2000);
l_cnt number := 0;
l_owner varchar2(25) := 'OWNER1';
l_index_cnt number := 4;
type txn_rec_tab_cnt is record
(
 tab_name varchar2(70),
 tab_aff_rows number(6):= 0
);
type t_tab_cnt is table of txn_rec_tab_cnt index by binary_integer;
txn_tab_cnt t_tab_cnt;
cursor c1 is
select ref_num from trans
where country_code = 'KK';
cursor c2 is
select a.owner||'.'||a.table_name table_name,b.column_name
from all_tab_columns a,all_tab_columns b
where a.column_name = 'CTRY'
and a.table_name = b.table_name
and b.column_name in ('REF_NUM','BILL_REF_NUM','FLDR_T2_ID','TXN_REF_NUM')
and a.owner = l_owner
and b.owner = l_owner;

begin
for curs1 in c1 loop
l_cnt := l_cnt + 1;
l_index_cnt := 4;
for curs2 in c2 loop
l_where_clause := ' where '||curs2.column_name || ' = :col1';
execute immediate 'update '||curs2.table_name||' set ctry_cd = ''KK'''||
l_where_clause
using curs1.ref_num;
txn_tab_cnt(l_index_cnt).tab_name := curs2.table_name;
txn_tab_cnt(l_index_cnt).tab_aff_rows:=
txn_tab_cnt(l_index_cnt).tab_aff_rows+sql%rowcount;
l_index_cnt :=  l_index_cnt + 1;
end loop;
if mod(l_cnt,l_commit_interval) = 0 then
commit;
end if;
end loop;
commit;
for j in 1..txn_tab_cnt.count loop
dbms_output.put_line('No of rows updated in '||txn_tab_cnt(j).tab_name||' =
'||txn_tab_cnt(j).tab_aff_rows);
end loop;
end;
/



                      rjamya

                      <rjamya@xxxxxxxxx>         To:
manoj.gurnani@xxxxxxxxxxxxx

                      Sent by:                   cc:
oracle-l@xxxxxxxxxxxxx

                      oracle-l-bounce@fr         Subject: Re: PL/SQL
question
                      eelists.org



                      09/28/2005 06:42

                      PM

                      Please respond to

                      rjamya






You don't show us the code, you don't tell us what version,platform, you
don't tell us how much time it takes and you don't tell us how much time ti
should take.

Sorry, the crystal ball is broken, come back in 3 weeks.

ps: 1 lakh is one hundred thousand.
Raj

On 9/28/05, manoj.gurnani@xxxxxxxxxxxxx <manoj.gurnani@xxxxxxxxxxxxx >
wrote:

Hi,
      I've a cursor which retrieves about 3 lakh recs from a table.(master)

based on column value retrieved from cursor for each rec,there are other
tables (detail) to be updated.
The detail tables have large volumes of data.
the question is how can the performance be improved to achieve the desired
result.




This e-Mail may contain proprietary and confidential information and is
sent for the intended recipient(s) only.
If by an addressing or transmission error this mail has been misdirected to
you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction,
dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its
attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in
--
http://www.freelists.org/webpage/oracle-l




This e-Mail may contain proprietary and confidential information and is sent 
for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to 
you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, 
dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its 
attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in
--
http://www.freelists.org/webpage/oracle-l

Other related posts: