I am trying to update the first two rows of a column from null to Y so that a user should be able to select two images.
Can you please tell me how to fix the query below;
DECLARE CURSOR tp_Identifier_cur
IS
select distinct TP_IDENTIFIER
from IMAGES
ORDER BY TP_IDENTIFIER ASC;
l_tp_Identifier tp_Identifier_cur%ROWTYPE;
BEGIN
OPEN tp_Identifier_cur;
LOOP
FETCH tp_Identifier_cur INTO l_tp_Identifier;
EXIT WHEN tp_Identifier_cur%NOTFOUND;
UPDATE IMAGES SET OMG = 'Y'
where TP_IDENTIFIER = l_tp_Identifier.TP_IDENTIFIER
and rownum <= 2
order by Image_identifier;
END LOOP;
CLOSE tp_Identifier_cur;
END;
Best Answer
You don't need a cursor for this:
If you want 2 rows per TP_IDENTIFIER, I'd go for a window function: