I've got the following Java method (which I've loaded into an Oracle 11g database from its JAR using loadjava)
public int GatewayClientPoolHA( String[] DAUTAddresses,
int[] DAUTPortArray,
String sslKeystorePath,
String sslKeystorePass )
Now, I want to wrap this Java method in a PL/SQL function, but I'm getting a PLS-00258 error with the following code. I presume this is because of the array input parameters? Any suggestions?
CREATE OR REPLACE PACKAGE daut_2fa IS
TYPE daut_addresses_type IS TABLE OF VARCHAR2(50) INDEX BY BINARY_INTEGER;
TYPE daut_port_type IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;
FUNCTION GatewayClientPoolHA (
DAUTAddresses IN daut_addresses_type,
DAUTPortArray IN daut_port_type,
sslKeystorePath IN VARCHAR2,
sslKeystorePass IN VARCHAR2
) RETURN INTEGER;
END daut_2fa;
/
SHOW ERROR
CREATE OR REPLACE PACKAGE BODY daut_2fa IS
FUNCTION GatewayClientPoolHA (
DAUTAddresses IN daut_addresses_type,
DAUTPortArray IN daut_port_type,
sslKeystorePath IN VARCHAR2,
sslKeystorePass IN VARCHAR2
) RETURN INTEGER IS LANGUAGE JAVA
NAME 'daut.GatewayClientPoolHA(java.lang.String[], int[], java.lang.String, java.lang.String) return int';
END daut_2fa;
It's actually the constrained return type it doesn't like;
INTEGERis a constrained number, so that is causing the PLS-00258 error:You need to
RETURN NUMBERinstead so it isn't constrained:... but then you'll hit (in 11gR2 anyway):
And even with unindexed PL/SQL tables you'll still get:
So you need schema level (not PL/SQL) collections, created as separate types before your package is created:
The collection not being indexed may be a problem for you though, as you're presumably putting related values in the same index position in both lists. You may need an object type and a single table of those instead, if you can unpack that as a structure in Java. Something like:
and then
There's an example in the documentation that passes an object type; this is just taking it further and passing a collection of objects, so you should be able to refer to each STRUCT element of the array, using the appropriate type mapping for each field of the object/structure. Though I haven't actually tried that part.
Or use a single
varrayof strings but concatenate the port value (e.g.'127.0.0.1:1521') and decompse that in Java - which might be easier...