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.

Unanswered: Problem with a cursor

I AM TRYING TO FETCH DATA FROM A TABLE THROUGH A CURSOR WHICH MIGHT CONTAIN MSISDN NUMBERS IN DUPLICATE. I HAVE TO FETCH THEM AND THEN PERFORM A SUM FUNCTION FOR THE 'MOU' COLUMN OF THOSE DUPLICATE MSISDN NUMBERS.
THIS CURSOR IS WORKING VERY SLOW. IT TAKES 5 MINUTES TO INSERT OR UPDATE ONLY 1000 RECORDS.
KINDLY HELP HOW TO SPEED UP THE EXECUTION TIME. OR SUGGEST IF THERE IS SOMETHING WRONG WITH THE LOGIC I AM EXECUTING..
THE CODE IS AS FOLLOWS:

You are using procedural processing, where you do something for each record in TEMP_VOICE_USAGE. The "something" is the execution of 2 SQL statements (1x INSERT or UPDATE and 1x DELETE). It is not very surprising that it performs poorly for you. Especially if you consider that the DELETE is a searched-delete and not a positioned-delete. (A positioned delete uses WHERE CURRENT OF <cursor>.)

You may want to use SQL in a set-oriented fashion. You may want to use the MERGE statement. Another option would be to have 1x INSERT for all new records, 1x UPDATE for all existing ones and then a single DELETE (no loops):