Intermediate

14-10.

Are parameters in PL/SQL passed by value or by reference?

14-11.

How many RETURNs should the executable section of a function contain?

14-12.

Should you include RETURNs in your function’s exception section?

14-13.

Should the following function have an exception section? If so, what should it handle?

CREATE OR REPLACE FUNCTION deptname (
   id_in IN department.department_id%TYPE
   )
   RETURN VARCHAR2
IS
   retval department.name%TYPE;
BEGIN
   SELECT name
     INTO retval
     FROM department
    WHERE department_id = id_in;

   RETURN retval;
END deptname;
/

14-14.

What are the restrictions on setting default values for parameters?

14-15.

What advantage is there to providing default values for parameters?

14-16.

Suppose that five years ago, a developer wrote a procedure with the following header:

PROCEDURE calc_totals (
   department_id_in IN department.department_id%TYPE)

There are many calls to this procedure in a variety of production applications. A new requirement has now been requested by users to be able to calculate totals per department and also for sections within departments. How would you change the header of calc_totals so that:

  • Developers can pass in the section ID in addition to the department ID.

  • Existing calls to calc_totals will remain valid.

14-17.

Can you skip over parameters when you call a procedure or function?

14-18.

Given the header for the calc_profit procedure:

PROCEDURE calc_profit (company_id_in IN NUMBER, profit_out OUT NUMBER fiscal_year_in IN NUMBER, profit_type_in IN VARCHAR2 := 'NET_PROFITS', ...

Get Oracle PL/SQL Programming: A Developer's Workbook 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.