java nested,在java中使用nested_tables

本文档展示了如何在Java中从PL/SQL过程的OUT参数接收嵌套表类型。首先创建了一个Oracle的自定义对象类型和嵌套表类型,然后定义了返回该类型的过程。在Java中,通过CallableStatement设置输入参数和注册输出参数,执行查询时需要注意类型匹配。当获取结果时,将OUT参数转换为Object数组并遍历以打印每个元素。提供的代码示例详细解释了处理过程。
摘要由CSDN通过智能技术生成

How do I receive a nested table in java from pl/sql procedure's OUT parameter? Here is my example code.

Connection connection = utilities.getConnectionToDb();

CallableStatement callableStatement = connection.prepareCall("{call procedure_name(?,?)}");

callableStatement.setLong(1, 23456);

callableStatement.registerOutParameter(2, Types.ARRAY);

callableStatement.executeQuery();

But when I try executing it I get the error

PLS-00306: wrong number or types of arguments in call to 'procedure_name'

I am sure that the number of arguments are correct.

解决方案

The way a nested table is recieved from an OUT parameter depends on how the table is nested consider a simple array type

object type

CREATE OR REPLACE

TYPE HR.TNAME

AS

OBJECT( NO1 NUMBER,

NAME VARCHAR2(10)

);

table type

CREATE OR REPLACE

TYPE HR.ITYPE_CUSTOM

IS TABLE OF tname;

Procedure

CREATE OR REPLACE PROCEDURE HR.p_schema_level_out(IN1 IN varchar2,p_det OUT itype_custom)

AS

lc_var itype_custom := itype_custom();

BEGIN

lc_var.extend;

lc_var(1) := TNAME(NO1 => 1,NAME => 'TRAIL1');

lc_var(1).no1 := 1;

lc_var(1).name := 'qwe';

p_det:= lc_var;

END;

/

The above procedure which returns a custom array type can be handled by

try {

stmt = con.createStatement();

// -----------------------------------------------------

// Call PL/SQL Procedure

// -----------------------------------------------------

String s1 = "begin p_schema_level_out(?,?); end;";

cstmt = (OracleCallableStatement) con.prepareCall(s1);

cstmt.setString(1, "something");

cstmt.registerOutParameter(2, Types.ARRAY, "ITYPE_CUSTOM");

cstmt.execute();

Object[] data = (Object[]) ((Array) cstmt.getObject(2)).getArray();

for (Object tmp : data) {

STRUCT row = (STRUCT) tmp;

for (Object attribute : row.getAttributes()) {

System.out.println(attribute);

}

cstmt.close();

stmt.close();

}

} catch (SQLException e) {

e.printStackTrace();

}

This works as a base on how you can recieve a table type i could still help you through if you can post your nested table type

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值