Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. What’s Code Without Variables? > I take exception to your declaration sectio...

I take exception to your declaration section.

Perform complex variable initialization in the execution section.

Problem: The exception section of a block can only trap errors raised in the execution section.

That is a little fact that many PL/SQL developers don’t realize, and one that causes lots of headaches. Delaware writes the following packaged function, a classic “getter” of a private variable:

PACKAGE fe_config
IS
   FUNCTION get_worst_excuse  RETURN VARCHAR2;
END fe_config;
/

PACKAGE BODY fe_config
IS
   c_worst_excuse CONSTANT VARCHAR2 (20) :=
      'The dog ate my homework. Really.';

   FUNCTION get_worst_excuse  RETURN VARCHAR2
   IS
   BEGIN
      RETURN c_worst_excuse;
   END get_worst_excuse;
BEGIN
   DBMS_OUTPUT.put_line ('Initialization logic here');
     ... lots of initialization code ...
EXCEPTION
   WHEN OTHERS
   THEN
      fe_errmgr.log_and_raise_error;
END fe_config;
/

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint