I noticed you're always updating the row you just read from the cursor, but the UPDATE re-reads the row. Add FOR UPDATE OF OUTCOST to the DECLARE CURSOR. Then at the bottom of loop in the UPDATE, lose the test on ID, and instead do WHERE CURRENT OF LINES_cursor. There are no references to @ID other than the UPDATE statement, so you don't need ID in the cursor and you don't need the @ID variable.