java - 将对象数组从 PLSQL 传递到 Java 函数时出错

标签 java oracle plsql java-stored-procedures varray

我有一个 abc_type 类型和一个 abc_table 类型的数组。 我正在尝试将对象数组传递给 java 函数。

create type abc_type authid definer as object
  ( file_name    varchar2(5000),
    file_size    number,
    file_paths   varchar2(4000)
    );
create type abc_table as table of abc_type;

create or replace and compile java source named "Hello" as
public class Hello
{
  public static String world(String str,Array str2)
  {
    return "Hello world - "+ str;
  }
}
/

CREATE OR REPLACE FUNCTION helloworld (
str_in in varchar2,
str2_in in abc_table
)
RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'Hello.world (java.lang.String,oracle.sql.Array) return java.lang.String';
/

declare 
str varchar2(200):='def';
zipfiles abc_table:=abc_table();
begin
zipfiles.extend(1);
zipfiles(1) := abc_type('aaa',22,'bbb');
dbms_output.put_line('test:'||helloworld('abc',zipfiles));
end;
/

一切都编译正常,但我收到错误ORA-29541:无法解析class .Hello。 如果我用 String/Varchar2 替换 Array 类型,效果很好。

标题

最佳答案

修复了以下更改

添加了导入语句

import oracle.sql.*; // I had added this earlier, but this alone didn't fix the issue.
import java.sql.*;

//With the above, I was able to pass the object, but I was not able to reference the object.

添加了异常处理。

throws IOException,java.sql.SQLException to the function.

最终代码(还有一些其他更改)

create or replace and compile java source named "Hello" as
package abc;

    import oracle.sql.*;
    import java.sql.*;
    import java.io.*;
    import java.util.ArrayList;
    import java.util.zip.*;
    import java.sql.Connection;

    public class Hello extends Object
    {
      public static void world(String str,String[] strout, oracle.sql.ARRAY arr) throws IOException,java.sql.SQLException
      {
          Datum[] ZipTyp = ((ARRAY)arr).getOracleArray();
          strout[0] = "Output - "+ str + ","+arr.getSQLTypeName()+ ","+ java.lang.reflect.Array.getLength(ZipTyp);
      }
    }
    /

    CREATE OR REPLACE PROCEDURE helloworld2 (
    str_in IN varchar2,
    str_out OUT varchar2,
    arr_in in abc_table
    )AS
    LANGUAGE JAVA 
    NAME 'abc.Hello.world (java.lang.String,java.lang.String[],oracle.sql.ARRAY)';
    /

    declare 
      str varchar2(200):='def';
      zipfilelist abc_table := abc_table();
      l_in v_table := v_table();
    begin
      zipfilelist.extend(2);
      zipfilelist(1) := abc_type('aaa1',11,'bbb1');
      zipfilelist(2) := abc_type('aaa2',22,'bbb2');
      helloworld2('abc',str,zipfilelist);
      dbms_output.put_line('test:'||str);
    end;
    /

关于java - 将对象数组从 PLSQL 传递到 Java 函数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35421471/

相关文章:

java - DateTimeFormatter异常解析其自己的打印结果

oracle - 基于触发器的分区创建

oracle - 删除全局临时表

java - 从没有 "ORA-29532 Java call terminated by uncaught Java exception"的 Java 存储过程中引发错误

Java JUnit、接口(interface)、类标题

java - 如何将用户输入保存为类实例的名称?

java - 上传多部分文件时出现 FileNotFoundException - Spring boot

组中任何非特定值的 SQL 聚合函数

sql - 将值列表与表进行比较

SQL:按 "business days"分组