我正在尝试编写一个 oracle Java 存储过程来返回一个可以用作表的数据结构,以便进行选择。最终结果必须如下所示:
select * from TABLE(get_table('astring','anotherstring'));
我已经定义了这样的 oracle 类型:
CREATE OR REPLACE TYPE "TEST_JAVA_TYPE" IS OBJECT (
name VARCHAR2(255),
value VARCHAR2(255)
)
CREATE OR REPLACE TYPE "TEST_JAVA_TYPE_TABLE" AS TABLE OF TEST_JAVA_TYPE;
我的 Java 代码如下所示:
import java.util.ArrayList;
import java.util.List;
public class TableTester {
public static ARRAY getTable() {
List<TEST_JAVA_TYPE> list = new ArrayList<TEST_JAVA_TYPE>();
TEST_JAVA_TYPE t1 = new TEST_JAVA_TYPE();
TEST_JAVA_TYPE t2 = new TEST_JAVA_TYPE();
t1.name = "Joe";
t1.value = "A";
t2.name = "Jim";
t2.value = "B";
list.add(t1);
list.add(t2);
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
ArrayDescriptor dsc = ArrayDescriptor.createDescriptor("TEST_JAVA_TYPE_TABLE", conn);
return new ARRAY(dsc, conn, list.toArray());
}
static class TEST_JAVA_TYPE {
public String name;
public String value;
}
}
我这样调用java代码:
FUNCTION get_table(conn_type VARCHAR2, cube_name VARCHAR2) RETURN
TEST_JAVA_TYPE_TABLE AS LANGUAGE JAVA
NAME 'TableTester.getTable() return oracle.sql.ARRAY';
当我运行这个时,我得到
ORA-00932: inconsistent datatypes: expected a Java type at argument position 2 to which some Oracle value can be converted got something else
我如何正确转换/映射它?