4-12. Executing Packaged Procedures and Functions

Problem

You want to execute one of the procedures or functions contained within a package.

Solution

Use the package_name.object_name notation to execute a particular code object within a package. For instance, the following block of code executes the GRANT_RAISES procedure that is contained within the PROCESS_EMPLOYEE_TIME package.

BEGIN
    process_employee_time.grant_raises(.03,4000);
  END;

The previous code block executes the GRANT_RAISES function, passing .03 for the percentage of increase and 4000 for the upper bound.

How It Works

Dot notation is used for accessing members of a package. Similar to other languages such as Java, dot notation can be used to access any publically accessible member of the package. Any variable, function, or procedure that is contained in the package specification can be accessed using the dot notation. Therefore, if your package contained a constant variable within its specification that you wanted to access, it would be possible to do so from outside the package.

For a schema to access and execute package members, it must have the appropriate permissions. To grant EXECUTE permission on a package that you own, use the following syntax:

GRANT EXECUTE ON package_name TO user_name;

Dot notation works from within other procedures or functions. It can also be used from the SQL*Plus command line using the EXEC command.

Image Note In most cases, if a package is being used by another schema, then it is a good idea to create a public synonym for that package within the database. This will help decrease issues while attempting to reference the package and its programs from the different schema because you will not need to specify the schema name in order to qualify the call. Please see Recipe 4-13 for more information regarding public synonyms.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.217.40