I am trying to execute a cursor and want it to complete the loop even if there is some exception.
What I trying to do is "catch" all the exception and probably log something or do nothing and then return back to the flow . Here is how the code looks like:
FOR line IN my_cursor
LOOP
begin
if<condition> then
GOTO pass;
else
<<do_something>>
exception
when others then
sys.dbms_output.put_line('say something');
end if;
<<pass>> null;
end
END LOOP;
The script doesn’t compile.
There is probably some syntax error with the exception, but I am also not aware of semantics very well. Like I am not sure if you can return back to execution flow after handling an exception.
p.s: The DB is 10g and there is not CONTINUE in it. Hence using GOTO.
Put the code that you want to execute within the loop in it’s own block and then you can use that blocks exception section to handle any problems during the loop iteration.
Once the exception for that iteration is handled, the next loop iteration will start
e.g.:
To illustrate this further, in the example below, I have declared a local variable of type exception. I am looping through numbers 1 to 10, during the second loop iteration, the if statement is true and processing passes to the exception handler. Once the exception is handled, the next iteration of the loop begins.