Your question is a little ambiguous. Comparing two cursors can be a performance nightmare having to fetch a row from the first cursor then compare it to all of the rows from the second cursor and repeating this for all of the rows in the first cursor. Your solution might be as simple as using the merge that hans_vd shows, although I suspect that there are numerous where clauses in the select statements of your cursors that may complicate things. Post the select statements for your cursors and the update and insert statements here and we can see if there is an easier means of accomplishing your intent.
Main Topics
Browse All Topics





by: hans_vdPosted on 2006-10-31 at 05:42:20ID: 17841776
You can do it in 1 statement (modify the ON clause so that the fields that should correspond are in it) :
MERGE INTO xyz
USING (
SELECT col1A, col21, col3A, col4A
FROM abc) a
ON (xyz.col1B = a.col1A AND xyz.col2B = a.col2A)
WHEN MATCHED THEN
UPDATE SET xyz.col3B = a.col3A, xyz.col4B = a.col4A
WHEN NOT MATCHED THEN
INSERT (xyz.col1B, xyz.col2B, xyz.col3B, xyz.col4B)
VALUES (a.col1A, a.col2A, a.col3A, a.col3A)