tags:

views:

628

answers:

1

I've defined VARRAY of a user-defined type such as this :

CREATE OR REPLACE TYPE TEST_T  AS OBJECT 
  (C1 VARCHAR2(20 BYTE), C2 VARCHAR2 (11 Byte));
CREATE OR REPLACE TYPE ARRAY_TEST_T AS VARRAY(200) OF TEST_T;

Is it possible to create a java stored function/procedure that accepts VARRAY or user-defined type as IN parameter ?

If it is possible what should I replace "??????" with :

CREATE OR REPLACE FUNCTION FOOBAR (p1 IN ?????? )
RETURN VARCHAR2 AUTHID CURRENT_USER AS
LANGUAGE JAVA
NAME 'foobar.FoobarFunction.test_function(?????? array) return java.lang.String';


package foobar;
public class FoobarFunction {
    public static String test_function(?????? array) {
        return "ok";
    }
}
A: 

Answering my own question. Here is the solution that worked for me.

CREATE OR REPLACE FUNCTION FOOBAR (p1 IN ARRAY_TEST_T ) 
RETURN VARCHAR2 AUTHID CURRENT_USER AS
LANGUAGE JAVA
NAME 'foobar.FoobarFunction.test_function(java.sql.Array)
      return lava.lang.String';


package foobar;
public class FoobarFunction {
    public static String test_function(java.sql.Array array) {
        final Object[] content = (Object[]) array.getArray();
        for (Object c : content) {
                // expecting java.sql.Struct type for c;

                // get TEST_T attribute values for c1 and c2
                final Object[] attrs = ((java.sql.Struct) c).getAttributes();
                String c1 = (String) attrs[0];
                String c2 = (String) attrs[1];
            .......
        }

        return null;
    }
}
mtim