Put the code you want to execute in the loop in its own block, and then you can use this block exception block to handle any problems during the loop iteration.
As soon as the exception for this iteration is processed, the next iteration of the loop will start
eg:.
for line in my_cursor loop begin <<do_something>> exception <<do_exception_processing>> end; end loop;
To illustrate this further, in the example below, I declared a local type exception variable. I iterate over numbers from 1 to 10, during the second iteration of the loop, the if statement is true, and the processing goes to the exception handler. When an exception is thrown, the next iteration of the loop begins.
begin for i in 1 .. 10 loop declare my_exception exception; begin if i = 2 then -- if you need to do some processing then you would enter it -- here and then when you want to enter the exception section -- you would add the line below raise my_exception; end if; exception when my_exception then dbms_output.put_line('in exception section'); end; end loop; end;
Ian carpenter
source share