O'Reilly logo

Oracle PL/SQL Best Practices by Steven Feuerstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required