PL/SQL 对象成员函数 - java 方法

PL/SQL object member function - java method

我正在尝试创建一个成员函数调用 java 方法的 oracle 对象。它必须是成员函数,而不是静态函数。

Java class:

Create or Replace Java Source Named "Hello" As
public class Hello {
  public String World() { return "Hello World!"; }
}

对象:

Create or replace type T_HelloW as object(
helloID int,
member function HelloWorld return varchar2 as
language java name 'Hello.World() return java.lang.String');

Table 创建和数据插入:

create table hellos of T_HelloW;
insert into hellos values(1);

但是当我尝试调用它时:

select h.HelloWorld() from hellos h;

我收到错误:

ORA-00932:不一致的数据类型:应在位置 1 有一个 IN 参数,它是一个 Oracle 类型的实例,可转换为用户定义的实例 Java class 获得了一个 Oracle 类型无法转换为 java class

  1. 00000 - "inconsistent datatypes: expected %s got %s"

*原因:
*行动:

我有红色http://docs.oracle.com/cd/B19306_01/java.102/b14187/chsix.htm#BABJJFJC 实际上我找到的唯一信息。而且我看不出我遗漏了什么或做错了什么。

解决方案如 Sylvain Leroux 所建议。必须实现 SQLData 接口:

Create or Replace Java Source Named "Hello" As

import java.sql.*;
import java.io.*;

public class Hello implements SQLData {
  private int helloId;
  public String World() { return "Hello World!"; }
  String sql_type;

  public String getSQLTypeName() throws SQLException {
    return sql_type;
  }

  public void readSQL(SQLInput stream, String typeName) throws SQLException {
    sql_type = typeName;
    helloId = stream.readInt();
  }

  public void writeSQL(SQLOutput stream) throws SQLException {
    stream.writeInt(helloId);
  }
}