How to check if the exception block is available for the main block or routine of PLSQL

advertisements

I am trying to think of a validator that checks for Exception block available in PL/SQL block or any routine for the main body ( Highlighted in Bold).

Eg :

DECLARE
some data
      Procedure xyx IS
      BEGIN
      ....
      EXCEPTION
      ..
      END;  

BEGIN
some data
      BEGIN
      ....
      EXCEPTION
      ..
      END;
**EXCEPTION**
some data
      BEGIN
      ....
      EXCEPTION
      ..
      END;
END;

This is a simple example there can be many other scenarios but my need id to find that Exception block is avaialble for the main block of PL/SQL code.

Please let me know if you have any suggestion. Thanks


If you are using a Unix box and have GNU awk present, you can try this:

$ awk '/Procedure/ || p==1{if (/END/)p=0;else p=1;next}/BEGIN/{f++;next}/END/{f--;next}/EXCEPTION/ && f==1{print "Exception present"}' IGNORECASE=1 file.sql