How to Return a String Array From a Java Stored Procedure
(Doc ID 726937.1)
Last updated on MAY 25, 2023
Applies to:
Oracle Database - Enterprise Edition - Version 10.1.0.2 and laterOracle Database Cloud Schema Service - Version N/A and later
Gen 1 Exadata Cloud at Customer (Oracle Exadata Database Cloud Machine) - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Cloud Exadata Service - Version N/A and later
Information in this document applies to any platform.
Goal
If a Java Stored Procedure (JSP) is attempting to return a String array (String []) it can not be called directly from PL/SQL because currently Oracle does not have a type that maps to a Java String array (String []).
In order to implement a JSP that returns a String array as a parameter would be change the Java code from a String array into a type that Oracle supports. This is a fairly simple change, but if the Java object being called is obtained from a 3rd party vendor, modifying the code is not always feasible which is what this Note will address.
Based on the Oracle� Database JDBC Developer's Guide and Reference - 10g Release 2 (10.2) documentation there is a section listing the supported datatypes. Within the datatype mapping table there is nothing for String arrays. The closest would be to use a java.sql.Array type that maps to an Oracle Collection.
For this example, a Nested Table of type VARCHAR2 is created and used to create a java.sql.Array from the String array which is one of the supported types within PL/SQL. Assuming the original java class can't be modified, a new Java class will have to be created that returns a java.sql.Array type. Once within this new Java class, the String array will be converted to the java.sql.Array type and returned to the underlying procedure. Essentially the new java class is a "converter" that converts the Java type into the supported Oracle type.
Solution
To view full details, sign in with your My Oracle Support account. |
|
Don't have a My Oracle Support account? Click to get started! |
In this Document
Goal |
Solution |
Requirements |
Configuring |
Instructions |
Sample Code |
Sample Output |
References |