Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> time consuming UPDATE statement
Hi Gurus,
sorry for the long posting, but I am kinda lost.........
In the below procedure, there is an Update Stement. This is so timeconsuming, that the whole procedure takes 1 1/2 hrs to complete. If the UPDATE is removed, the whole thing is done in 3-4 mins. So there is nothing else eating up the time, but the Update....
BUT WHY ????????? I am on Oracle 7.3.4
Any hints are very welcome
Frank
Sellt Date, RateInc NUMBER(11), Counter NUMBER(11), Facility NUMBER(6), GROSS_REV NUMBER(11), Validations NUMBER(11), constraint prim_MonTransRateInc primary key (Sellt,RateInc,Facility) using index storage ( initial 5M next 5M MAXEXTENTS 121 PCTINCREASE 50 ) tablespace report) storage ( initial 5M next 5M MAXEXTENTS 121 PCTINCREASE 10 ) tablespace report;
----------------------------------------------------------------------------
---------------------------------
Fetched BOOLEAN := False;
CURSOR cur_move (EndDate DATE, maxlTotal number) IS
SELECT tmov.class, tmov.artid, tmov.ZIDLOCAL, tmov.ZIDDEVICE, tmov.vouch, tmov.TOTAL, tmov.TOTQUA, trunc(tmov.sellt) SELLT, tmov.Attrib, tmov.Facility FROM shadow.tmovement tmov, shadow.tShift TS WHERE trunc(ts.tEndTime) between to_date('01'||to_char(EndDate,'mmyyyy'),'ddmmyyyy') AND LAST_DAY(trunc(EndDate)) and trunc(tmov.Sellt) between to_date('01'||to_char(EndDate,'mmyyyy'),'ddmmyyyy') AND LAST_DAY(trunc(EndDate)) AND mod(tmov.devid,65536) between 600 and 899 and ts.ZIDSHIFTLOCAL=tmov.ZIDLOCAL and ts.ZIDSHIFTDEVICE=tmov.ZIDDEVICE and bshiftState = 4 and trunc(sellt)=to_date('01122003','ddmmyyyy') --and Total <= maxlTotal ORDER BY tmov.zidlocal, tmov.ziddevice, tmov.vouch,tmov.Sellt, tmov.class, tmov.artid;
rec_move cur_move%ROWTYPE; rec_oldmove cur_move%ROWTYPE; rec_sum db.MonTransRateInc%ROWTYPE; BEGIN Delete from db.MonTransRateInc; OPEN cur_move(EndDate, maxlTotal); rec_sum.Sellt :=to_date('01011977','ddmmyyyy'); rec_sum.RateInc :=0; rec_sum.Facility :=0; rec_sum.GROSS_REV :=0; rec_sum.Validations :=0; FETCH cur_move INTO rec_move; rec_oldMove:=rec_move; LOOP IF (rec_move.ZIDLOCAL <> rec_oldMove.ZIDLOCAL OR rec_move.ZIDDEVICE <> rec_oldMove.ZIDDEVICE OR rec_move.vouch <> rec_oldMove.vouch) OR (cur_move%NOTFOUND AND Fetched=True) THEN --dbms_output.put_line('U');
--dbms_output.put_line('Count='||to_char(rec_sum.Count));
--dbms_output.put_line('Gross_rev='||to_char(rec_sum.Gross_rev));
--dbms_output.put_line('Sellt='||to_char(Rec_Sum.Sellt,'ddmmyyyy
hh24miss'));
--dbms_output.put_line('RateInc='||to_char(Rec_sum.RateInc));
--dbms_output.put_line('Facility='||to_char(rec_sum.Facility));
Fetched:=False; UpDate db.MonTransRateInc Set Counter =Counter+rec_sum.Counter, Gross_rev =Gross_Rev+rec_sum.Gross_rev, Validations =ValiDations+rec_sum.validations where Facility=rec_sum.Facility and trunc(Sellt)=trunc(Rec_Sum.Sellt) and RateInc=Rec_sum.RateInc; If SQL%RowCount=0 then --dbms_output.put_line('I'); INSERT INTO db.MonTransRateInc (Sellt, RateInc, Counter, Facility, GROSS_REV, Validations) VALUES (rec_sum.Sellt, rec_sum.RateInc, rec_sum.Counter, rec_sum.Facility, rec_sum.Gross_rev, rec_sum.Validations); End If; rec_sum.RateInc:=0; rec_sum.Counter:=0; rec_sum.Facility:=-1; rec_sum.Gross_rev:=0; rec_sum.Validations:=0; rec_oldMove:=rec_move; end if; EXIT WHEN cur_move%NOTFOUND; IF rec_move.class in (0,1) THEN -- Gross Revenue Fetched:=True; rec_sum.gross_rev := rec_sum.gross_rev + rec_move.total; rec_sum.Facility :=rec_move.Facility; rec_sum.RateInc :=rec_move.Total; rec_sum.Sellt :=rec_move.Sellt; rec_sum.Counter :=rec_move.TotQua; END IF; -- Coupons used IF rec_move.class = 901 AND rec_move.ARTID != 10 AND rec_move.ARTID NOT between 13120 and 13139 THEN Fetched:=True; rec_sum.Validations := rec_sum.Validations + rec_move.total; END IF; -- Validation used IF rec_move.class = 901 AND (rec_move.ARTID between 13120 and 13139) THEN Fetched:=True; rec_sum.Validations := rec_sum.Validations + rec_move.total; END IF; --ISF used IF (rec_move.class = 901 AND rec_move.ARTID = 10 ) THEN Fetched:=True; rec_sum.Validations := rec_sum.Validations + rec_move.total; END IF; FETCH cur_move INTO rec_move; If Net=True then rec_sum.gross_rev := rec_sum.gross_rev + rec_sum.Validations; rec_sum.RateInc :=rec_sum.RateInc+rec_sum.Validations; rec_sum.Validations:=0; End If; END LOOP; -- loop CLOSE cur_move; commit;
![]() |
![]() |