Skip to Main Content
Oracle PL/SQL Programming: A Developer's Workbook
book

Oracle PL/SQL Programming: A Developer's Workbook

by Steven Feuerstein, Andrew Odewahn
May 2000
Intermediate to advanced content levelIntermediate to advanced
594 pages
11h 32m
English
O'Reilly Media, Inc.
Content preview from Oracle PL/SQL Programming: A Developer's Workbook

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Oracle Database 12c PL/SQL Programming

Oracle Database 12c PL/SQL Programming

Michael McLaughlin
Oracle PL/SQL for DBAs

Oracle PL/SQL for DBAs

Arup Nanda, Steven Feuerstein
Oracle PL/SQL For Dummies

Oracle PL/SQL For Dummies

Michael Rosenblum, Paul Dorsey

Publisher Resources

ISBN: 9781449324070Supplemental ContentErrata Page