Skip to next record in a pl sql Cursor with Bulk Collect

7.9k Views Asked by At

Please analyze the below code snippet and suggest a way to skip to the next record in the cursor.

BEGIN

OPEN cs_migrate_drop_ntd_object_status;

LOOP

    FETCH cs_migrate_drop_ntd_object_status BULK COLLECT INTO r_current_loc_equip LIMIT 200;

    FOR i IN 1..r_current_loc_equip.COUNT
    LOOP
        IF ( r_current_loc_equip(i).status = 'YES' ) THEN
            **-- Here I want to skip to next record fetched by the bulk collect cursor**
        ELSE
            Do something else;
1

There are 1 best solutions below

0
On BEST ANSWER

Use CONTINUE:

FOR i IN 1..r_current_loc_equip.COUNT
LOOP
    IF ( r_current_loc_equip(i).status = 'YES' ) THEN
        CONTINUE;
    ELSE...

You could also use it like this:

FOR i IN 1..r_current_loc_equip.COUNT
LOOP
    CONTINUE WHEN r_current_loc_equip(i).status = 'YES';
    Do something else;

(Better still, if you don't want to process rows where status='YES', don't select them in the cursor in the first place.)