Multiple choice technology databases

You want to create a PL/SQL block of code that calculates discounts on customer orders. This code will be invoked from several places, but only within the program unit ORDERTOTAL. What is the most appropriate location to store the code that calculates the discounts?

  1. A stored procedure on the server.

  2. A block of code in a PL/SQL library.

  3. A standalone procedure on the client machine.

  4. A block of code in the body of the program unit ORDERTOTAL.

  5. A local subprogram defined within the program unit ORDERTOTAL.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Since the discount calculation code will only be used within the program unit ORDERTOTAL and invoked from multiple places within that same unit, a local subprogram defined within ORDERTOTAL is the most appropriate choice. This encapsulates the logic, maintains scope within ORDERTOTAL, and avoids unnecessary global scope. A stored procedure (A) would be unnecessarily global, a PL/SQL library (B) is for broader reuse, and a standalone procedure on the client (C) is not a standard PL/SQL construct. Simply placing code inline (D) doesn't support the stated requirement of invocation from several places.