gpt4 book ai didi

java - ORA-03115 : unsupported network data type or representation

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:21 25 4
gpt4 key购买 nike

在提出这个问题之前,我已经用谷歌搜索了一段时间,但是现在找到了结果。我的代码尝试调用oracle包中的过程(我对oracle包不太熟悉),并且总是得到“ORA-03115:不支持的网络数据类型或表示法”,英文应该是“不支持的网络数据类型或表示法”。

下面是我的包装:

create or replace 
PACKAGE PKG_ACTIVITY_REPORT
IS
TYPE activity_report_item_type IS RECORD
( emp_id MERCHANT.merchant_id%TYPE,
emp_name MERCHANT.MERCHANT_NAME%TYPE,
emp_gender MERCHANT.MERCHANT_CODE%TYPE );
TYPE activity_report_items_type IS TABLE OF activity_report_item_type INDEX BY BINARY_INTEGER;

-- Procedure to retrive the activity report of given operator
PROCEDURE enquiry_activity_report(activity_report_items OUT activity_report_items_type);
END PKG_ACTIVITY_REPORT;

create or replace
PACKAGE BODY PKG_ACTIVITY_REPORT
IS
PROCEDURE enquiry_activity_report (activity_report_items OUT activity_report_items_type)
IS
activity_report_item activity_report_item_type;
BEGIN
activity_report_item.emp_id := 300000000;
activity_report_item.emp_name := 'Barbara';
activity_report_item.emp_gender := 'Female';

activity_report_items(1) := activity_report_item;

activity_report_item.emp_id := 300000008;
activity_report_item.emp_name := 'Rick';
activity_report_item.emp_gender := 'Male';

activity_report_items(2) := activity_report_item;

FOR i IN 1..activity_report_items.count LOOP
DBMS_OUTPUT.PUT_LINE('i='||i||', emp_id ='||activity_report_items(i).emp_id||', emp_name ='
||activity_report_items(i).emp_name||', emp_gender = '||activity_report_items(i).emp_gender);
END LOOP;
END enquiry_activity_report;

END PKG_ACTIVITY_REPORT;

我想从该过程返回一个数组,并从 java 调用该过程:

        conn = ds.getConnection();
String storedProc = "{call pkg_activity_report.enquiry_activity_report(?)}";
CallableStatement cs = conn.prepareCall(storedProc);
// register output parameter
cs.registerOutParameter(1, java.sql.Types.ARRAY);
cs.execute();
Array array = cs.getArray(1);
System.out.println(array);
cs.close();

运行时抛出异常。如何将 OUT 参数映射到 java 类型?请帮忙。

注意:当从 oracle sqldeveloper 运行此过程时,它可以正常工作。

DECLARE
ACTIVITY_REPORT_ITEMS RAMON.PKG_ACTIVITY_REPORT.ACTIVITY_REPORT_ITEMS_TYPE;
BEGIN

PKG_ACTIVITY_REPORT.ENQUIRY_ACTIVITY_REPORT(
ACTIVITY_REPORT_ITEMS => ACTIVITY_REPORT_ITEMS
);
END;

DBMS输出结果:

i=1, emp_id =300000000, emp_name =Barbara, emp_gender = Female
i=2, emp_id =300000008, emp_name =Rick, emp_gender = Male

最佳答案

现在我创建了 2 个架构级别类型:

CREATE OR REPLACE TYPE activity_report_item_type AS OBJECT( 
emp_id NUMBER,
emp_name VARCHAR2(30),
emp_gender VARCHAR2(30)
);

CREATE OR REPLACE TYPE activity_report_items_type AS TABLE OF activity_report_item_type;

并将PROCEDURE enquiry_activity_report移出包,独立制作,然后从java中成功调用它。

        conn = ds.getConnection();
String storedProc = "{call enquiry_activity_report(?)}";
CallableStatement cs = conn.prepareCall(storedProc);
// register output parameter
cs.registerOutParameter(1, OracleTypes.ARRAY, "ACTIVITY_REPORT_ITEMS_TYPE");
cs.execute();
Array array = cs.getArray(1);
ResultSet rs = array.getResultSet();
while (rs.next()) {
// why getObject(2) instead of getObject(1)?
Object elements[] = ((STRUCT) rs.getObject(2)).getAttributes();
System.out.println(elements[0]);
System.out.println(elements[1]);
System.out.println(elements[2]);
}

cs.close();

如果我将类型声明和过程放在包中,java代码将抛出异常,通知“未找到“ACTIVITY_REPORT_ITEMS_TYPE”的类型定义”。

关于java - ORA-03115 : unsupported network data type or representation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17992583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com