Name

STYL-04: Tag module END statements with module names.

Synopsis

Every program (indeed, every block of code; see [STYL-06: Self-document using block and loop labels. ]) has an END statement. You can, and should, append the name of the program to the end statement:

CREATE OR REPLACE PACKAGE BODY <pkgname>
IS
   PROCEDURE <procname> (...)
   IS BEGIN
      ...
   END <procname>;

   PROCEDURE <funcname> (...)
   IS BEGIN
      ...
   END <funcname>;

END <pkgname>;

Example

My package consists of 243 procedures and functions, stretching to over 5,000 lines. Without END labels, I could easily be confronted with code like this:

      END LOOP;
   END;
END;

Yikes! Wouldn’t it be so much better if my code had instead been written like this:

      END LOOP yearly_analysis;
   END best_seller_review;
END book_usage_pkg;

Benefits

This is merely good form for standalone programs. For packaged procedures and functions with code that goes on for hundreds or thousands of lines, however, named ENDs are crucial to improving the readability of that package.

Get Oracle PL/SQL Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.