Skip to content
Advertisement

Oracle optimize select after update status performance

I have a store procedure that will

  • Update maximum 500 rows status from 0 to 1
  • Return those rows to program via cursor

Here is my store procedure code

I want to optimize this performance and here is my question

  1. Should I replace in by exists

Replace

by

  1. Is there a better way than

    Save a string of ids like id1,id2,id3 after update row status

    Open cursor by select from string of ids

I appreciate for any suggestion.

Thank for your concern

Advertisement

Answer

Row-by-row processing is always slower and you are also creating the string of ids, which again takes time so overall performance is going down.

You can use the collection DBMS_SQL.NUMBER_TABLE to store the updated ids from the UPDATE statement using the RETURNING clause and use it in the cursor query.

Also, I have changed your update statement so that it does not use NOT IN and uses the LEFT JOINS and ROW_NUMBER analytical function for increasing the performance as follows:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement