I’ve been somewhat haphazardly grouping subsections of code in BEGIN…END blocks when it seems right. Mostly when I’m working on a longer stored procedure and there’s a need for a temporary variable in one spot I’ll declare it just for that portion of the code. I also do this when I want to identify and handle exceptions thrown for a specific piece of code.
Any other reasons why one should nest blocks within a procedure, function or another larger block of PL/SQL?
When you want to handle exceptions locally like this:
In this example, the exception is handled and then we carry on and process the next employee.
Another use is to declare local variables that have limited scope like this:
Mind you, wanting to do this is often a sign that your program is too big and should be broken up: