Chapter 15. Packages
A package is a named collection of procedures, functions, and data structures. A package has two parts: a specification, which lists its publicly available elements, and a body, which contains the actual implementations for the procedures and functions listed in the specification (the body can also contain private procedures, functions, and data structures that are available only within the package itself). This chapter tests your ability to define your own packages, create packaged data structures such as cursors, and use packages to encapsulate, or hide, the implementation details (e.g., data structures) of your programs.
Beginner
15-1. | Is it possible to execute a package? |
15-2. | If I want to call a procedure named “calc_totals” in the “financial_pkg” package, how would I write the code? |
15-3. | What are the exceptions to the dot-notation rule for packaged elements? In other words, when don’t you need to qualify a package element with its package name? |
15-4. | List all the packages referenced in the following piece of code, and say what types of packaged elements are used: DECLARE
v_new_pet pet.pet_id%TYPE;
v_last_appointment DATE;
BEGIN
IF pets_r_us.max_pets_in_facility >
TO_NUMBER (v_current_count)
THEN
/* Add another pet ... */
ELSE
DBMS_OUTPUT.PUT_LINE ('Facility is full');
END IF;
EXCEPTION
WHEN pets_r_us.pet_is_sick
THEN
...
WHEN NO_DATA_FOUND
THEN
RAISE_APPLICATION_ERROR (
-20555, 'Pet not found');
END; |
15-5. | Write a package specification that contains a DATE variable ... |