Publishing and Using Java in PL/SQL
Once you have written your Java classes and loaded them into the Oracle RDBMS, you can call their methods from within PL/SQL (and SQL)—but only after you “publish” those methods via a PL/SQL wrapper.
Call Specs
You need to build wrappers in
PL/SQL only for those Java methods you want to make available through
a PL/SQL interface. Java methods can access other Java methods in the
Java Virtual Machine directly, without any need for a wrapper. To
publish a Java method, you write a call
spec—
a PL/SQL program header (function or procedure)
whose body is actually a call to a Java method via the LANGUAGE JAVA
clause. This clause contains the following information about the Java
method: its full name, its parameter types, and its return type. You
can define these call specs as standalone functions or procedures, as
programs within a package, or as methods in an object type:
CREATE [OR REPLACE] --Only if a standalone program<Standard PL/SQL procedure/function header>
{IS | AS} LANGUAGE JAVA NAME 'method_fullname
(java_type_fullname
[,java_type_fullname
]...) [returnjava_type_fullname
]';
where java_type_fullname is the full name of the Java type, such as java.lang.String.
The NAME clause string uniquely identifies the Java method being wrapped. The fully qualified Java names and the call spec parameters, which are mapped by position only, must correspond, one to one, with the parameters in the program. If the Java method takes no arguments, code an ...
Get Oracle PL/SQL Programming, Third Edition 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.