It does not really make any sense to talk about running or executing a package, since a package is just a container for code elements. However, you will certainly want to run or reference those elements defined in a package.
A package owns its objects, just as a table owns its columns. To reference an element defined in the package specification
outside of the package itself, you must use the same dot notation to fully specify the name of that element. Below are some examples.
The following package specification declares a constant, an exception, a cursor, and several modules:
max_pets_in_facility CONSTANT INTEGER := 120;
CURSOR pet_cur (pet_id_in IN pet.id%TYPE) RETURN pet%ROWTYPE;
FUNCTION next_pet_shots (pet_id_in IN pet.id%TYPE) RETURN DATE;
PROCEDURE set_schedule (pet_id_in IN pet.id%TYPE);
To reference any of these objects, I preface the object name with the package name, as follows:
-- Base this constant on the id column of the pet table.
c_pet CONSTANT pet.id%TYPE:= 1099;
IF pets_inc.max_pets_in_facility > 100
OPEN pets_inc.pet_cur (c_pet);
v_next_appointment:= pets_inc.next_pet_shots (c_pet);
To summarize, there are two rules to follow in order to reference and use elements in
- When you reference elements defined in a package specification from outside of that package (an external program), you must use dot notation in the form package_name.element_name.
- When you reference package elements from within the package (specification or body), you do not need to include the name of the package. PL/SQL will automatically
resolve your reference within the scope of the package.