If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > table update

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-25-06, 03:45
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
table update

I have 3 million rows in table_a. I need to update all the 3 million rows for a specific field in chunks of 10,000 rows on each commit. Here's the script that I have, but it seems to have a problem --
It updates 10001 rows and then hangs. I waited for about 3 hours and still it keeps executing without any further updates. Where could be the problem ?

declare
i number := 0;
BegTime NUMBER;
EndTime NUMBER;
ElapsedTime NUMBER;
sv schema_a.table_a%rowtype;
cursor c1 is select * from schema_a.table_a ;
begin
BegTime := dbms_utility.get_time;
open c1;
loop
fetch c1 into sv;
exit when c1%NOTFOUND;
Update schema_a.table_a s
set s.SV_START_DATE = to_DATE('060101','YYMMDD')
Where to_Char(SV_START_DATE,'YYMMDD') = '060201';
i := i+1;
IF MOD(i,10000) = 0
THEN
COMMIT;
END IF;
end loop;
EndTime := dbms_utility.get_time;
ElapsedTime := (EndTime - BegTime)/100;
dbms_output.put_line('Total Elapsed time for the procedure to complete' ||
ElapsedTime || ' seconds');
commit;
end;
/
Reply With Quote
  #2 (permalink)  
Old 01-25-06, 05:13
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Actually, what your script does is update all rows where to_Char(SV_START_DATE,'YYMMDD') = '060201', 3 million times! No wonder it runs for quite a while...

Try just running this instead:

Code:
begin
	Update schema_a.table_a s
	set s.SV_START_DATE = to_DATE('060101','YYMMDD')
	Where to_Char(SV_START_DATE,'YYMMDD') = '060201';
	commit;
end;
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On