The ORA_JAVA
package includes Built-ins that provide routines
to create an array and to get and set the value of an array element. These arrays
are fully interoperable with Java arrays.
The ORA_JAVA.JARRAY
type is used to store references to created
arrays. For example:
PROCEDURE get_object_array IS
arr ORA_JAVA.JARRAY;
obj1 ORA_JAVA.JOBJECT;
...
The ORA_JAVA.JARRAY
type is a subtype of a ORA_JAVA.JOBJECT
,
so arrays can be persisted in the same manner as all other Java objects using
the global reference funtions. See Controlling
Java Object Persistence for more information.
Arrays can be created of any Java scalar type or of the java.lang.Object
type. The ORA_JAVA
package contains Built-ins that allow you to
create arrays of a specific type and of a designated length. Arrays can be returned
from function calls in the generated PL/SQL packages.
ORA_JAVA.NEW_java_type_ARRAY
Built-in to create
the arrayORA_JAVA.SET_java_type_ARRAY_ELEMENT
Built-in
to set the values of array elementsORA_JAVA.GET_java_type_ARRAY_ELEMENT
Built-in
to get the values of array elementsAnother convenient array Built-in is the ARRAY_LENGTH
function
that returns the maximum length of a specified array. This Built-in is commonly
used when an array object is returned from a Java method call and the length
of the array is unknown.
In the following example, the ORA_JAVA
Built-ins are used to create
an array with three elements, store integers in the first two element positions,
and store the sum of the two elements in the third position. The length of the
array is then sent to the message line.
PROCEDURE set_int_array IS
arr ORA_JAVA.JARRAY;
arg1 PLS_INTEGER;
arg2 PLS_INTEGER;
arg3 PLS_INTEGER;
BEGIN
arr := ORA_JAVA.NEW_INT_ARRAY(3);
ORA_JAVA.SET_INT_ARRAY_ELEMENT(arr, 0, 2);
ORA_JAVA.SET_INT_ARRAY_ELEMENT(arr, 1, 4);
arg1 := ORA_JAVA.GET_INT_ARRAY_ELEMENT(arr, 0);
arg2 := ORA_JAVA.GET_INT_ARRAY_ELEMENT(arr, 1);
arg3 := arg1 + arg2;
ORA_JAVA.SET_INT_ARRAY_ELEMENT(arr, 2, arg3);
message(' Array length is: ' || ORA_JAVA.GET_ARRAY_LENGTH(arr));
END;
Controlling Java Object Persistence
GET_java_type_ARRAY_ELEMENT Built-in
SET_java_type_ARRAY_ELEMENT Built-in