15-11. Embedding a Java Class Into a PL/SQL Package

Problem

You are interested in creating a Java class and making each of its methods and attributes available to PL/SQL in an organized unit of code.

Solution

Use a PL/SQL package to declare each of the attributes and methods that reside within the Java class, and then create separate call specifications for each of the Java methods within the PL/SQL package body. The following code demonstrates the creation of a PL/SQL package named EMP_PKG, which declares each of the methods that reside within the Employee Java class and makes them available to PL/SQL via call specifications that are implemented within the package body.

First, create the package header as follows:

CREATE OR REPLACE PACKAGE ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach 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.