tags:

views:

83

answers:

2
A: 

Three things occur to me.

I presume this is some test you are working on. But you have defined both cursors to execute exactly the same query. So that is one reason why you might be getting duplicate rows. Certainly, the lack of clear business logic in your question makes it hard for us to understand what you are trying to achieve.

The second is, you have a nested loop, looping through the records of one table within the records of another table. But you have neglected to join the rows selected by the inner cursor with the current row of the outer cursor. So each row in the vend_cursor will fetch the entirely the same set of rows within the product_cursor.

Lastly, the product_cursor is not sorted or filtered by the distinct keyword. Given the two previous points this may not matter. I just mention it for the sake of completeness.

APC
@Please see my comments
BALAMURUGAN
+1  A: 

Forgetting the use of cursors in SQL for now...

In any language, why would you declare an inner loop to have the same iteration as the outer loop? In this case both cursors are based on SELECT * FROM MYSEQ.

gbn
Please see my comments
BALAMURUGAN
@BALAMURGAN: the same answer applies. It's obvious that you are iterating over the **same set of records**.
gbn
@gbn see the Edit Cursor
BALAMURUGAN
@BALAMURGAN: Try and think about your questions before asking
gbn