Try using two cursor.
for ex cursor1 and cursor2.
place the cursor1 in the loop and compare it with cursor2 by advancing cursor2.
i mean by fetching values from cursor2 before fetching the values from cursor1.
In the loop fetching the values from cursor1 and cursor2 normallty and compare them ...