O'Reilly logo

Oracle PL/SQL Programming: A Developer's Workbook by Andrew Odewahn, 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

Intermediate

Q:

14-10.

In all versions of PL/SQL before Oracle 8.1, IN parameters are passed by reference, while OUT and IN OUT parameters are passed by value.

Q:

14-11.

You should try to have just one RETURN statement in the executable section of your functions, preferably the last line in the section. Think of the body of the function as a funnel, with all the other lines in the executable section narrowing down to a single RETURN statement at the end of the function. Here is a “template” for such a function:

CREATE OR REPLACE FUNCTION function_name RETURN datatype
IS
   retval datatype;
BEGIN
   ... Your code here...

   RETURN retval;

EXCEPTION
   WHEN OTHERS
   THEN
      RETURN NULL;
END function_name;
/

Why should you have only one RETURN statement? Multiple RETURN statements translate to multiple possible exit points from the function. Such a structure makes it harder for developers to understand, debug, and maintain the code.

Q:

14-12.

There is no one right or wrong answer to this question. Generally, you want to design your functions so that they are as reusable as possible, to avoid code redundancy and maintenance headaches. As a rule, a function is more useful if it does not allow exceptions to propagate out unhandled for predictable kinds of problems. So you should include an exception handler with a RETURN NULL;—or some other value that indicates something went wrong—for errors that might occur in the function. You could then allow other exceptions to go unhandled.

Q:

14-13.

You should include an exception ...

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