简体   繁体   English

使用PL SQL表类型的参数对Oracle存储过程进行JDBC调用

[英]JDBC Call to Oracle Stored Procedure with parameters of type PL SQL table

I need to make JDBC call to a procedure with parameters of type PL/SQL table. 我需要对参数类型为PL / SQL表的过程进行JDBC调用。 I am trying with struct object. 我正在尝试使用struct对象。 But I am not doing some thing correct. 但是我没有做正确的事情。 I get the error: ORA-04043: object "scott"."objListStruct" does not exist. 我收到错误消息:ORA-04043:对象“ scott”。“ objListStruct”不存在。

Here is the code snippet: 这是代码片段:

conn = Application.getDBConnection();
                CallableStatement cStmt = null;
                cStmt= conn.prepareCall("{call package1.procedure1"+"(?)}");
                Struct objListStruct = conn.createStruct("objListStruct",
                                objNameArr.toArray());
                cStmt.setObject(1, objListStruct,Types.STRUCT);

The parameter, "?" 参数“?” for this procedure, is of type: 对于此过程,类型为:

TYPE t_name IS TABLE OF TABLE1.name%TYPE

Any insight to make this work is highly appreciated. 对此工作的任何见解都受到高度赞赏。 Thanks 谢谢

Two things: 两件事情:

1) The easiest way is to not pass anything to the procedure. 1)最简单的方法是不向过程传递任何内容。 Create a global temporary table, insert all the data you need, then call the proc, which reads from your temporary table. 创建一个全局临时表,插入所需的所有数据,然后调用proc,该proc从您的临时表中读取。 Just be careful that you aren't autocommitting your connection. 请注意不要自动提交连接。

2) If you have to pass in an array, you'll need to drop down and use the Oracle Array type. 2)如果必须传递数组,则需要下拉列表并使用Oracle Array类型。 The Oracle array type will bind to the table type. Oracle数组类型将绑定到表类型。 So something similar (NOTE: code not tested!) to this: 因此类似于以下内容(注意:未经测试的代码!):

Object[] arrayObject = { x, y };

ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(
        "MY_SCHEMA.MY_ARRAY_TYPE", conn);
ARRAY myArray = new ARRAY(descriptor, conn, arrayObject);


CallableStatement cs = conn
        .prepareCall("{ call package1.procedure1(?)}");
cs.setArray(1, myArray);
cs.execute();
conn.close();
String[] varStrArr = varArr.toArray(new String[compNameArr.size()]);
OracleCallableStatement cStmt = (OracleCallableStatement) 
conn.prepareCall("BEGIN SCHEMA.PACKAGE.procedure(?);END;");
cStmt.setPlsqlIndexTable(1,varStrArr,varStrArr.length,varStrArr.length,
                        OracleTypes.VARCHAR, 50);
cStmt.execute();

The above code works. 上面的代码有效。 More reference material is available at: Binding IN Parameters 有关更多参考资料,请参见: 绑定IN参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM