[英]How to map TYPE TABLE OF VARCHAR2(5) in java?
I have a procedure with the signature below. 我有一个带有下面签名的程序。
CREATE OR REPLACE PACKAGE BODY MYSCHEMA.MYPACK
AS
PROCEDURE GETBOX (DSSO_BoxNumber IN VARCHAR2,
CreateDateTime OUT tCreateDateTime,
ReceiptDateTime OUT tReceiptDateTime,
CSCBoxNumber OUT tCSCBoxNumber,
DSSOBoxNumber OUT tDSSOBoxNumber,
PackID OUT tPackID,
RequestID OUT tRequestID,
ExceptionID OUT tExceptionID,
Name OUT tName,
FolderID OUT tFolderID,
ClosedDateTime OUT tClosedDateTime,
OpenStatus OUT tOpenStatus,
RequestOpenStatus OUT tRequestOpenStatus,
RETURNED OUT tRETURNED)
...
The cutom type definitions are as below. cutom类型定义如下。
CREATE OR REPLACE PACKAGE MYSCHEMA.MYPACK
AS
TYPE tCreateDateTime is TABLE of VARCHAR2(15)
INDEX BY BINARY_INTEGER;
TYPE tReceiptDateTime is TABLE of VARCHAR2(15)
INDEX BY BINARY_INTEGER;
TYPE tCSCBoxNumber is TABLE of VARCHAR2(20)
INDEX BY BINARY_INTEGER;
TYPE tDSSOBoxNumber is TABLE of VARCHAR2(20)
INDEX BY BINARY_INTEGER;
TYPE tPackID is TABLE of VARCHAR2(20)
INDEX BY BINARY_INTEGER;
TYPE tRequestID is TABLE of VARCHAR2(20)
INDEX BY BINARY_INTEGER;
TYPE tExceptionID is TABLE of VARCHAR2(20)
...
Can anyone please help, how to register the out parameters in java? 任何人都可以请求帮助,如何在java中注册out参数?
I have tried the following, but no luck. 我试过以下,但没有运气。
cs.setString(1, "XYZ123");
cs.registerOutParameter(2, Types.ARRAY,"MYSCHEMA.MYPACK.tCreateDateTime");
...
Getting the below error. 得到以下错误。
java.sql.SQLException: invalid name pattern: MYSCHEMA.MYPACK.tCreateDateTime
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java:463)
at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java:362)
at oracle.sql.ArrayDescriptor.initPickler(ArrayDescriptor.java:1756)
at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:272)
...
We have checked that the schema has access to the procedure and it is defined in the master schema. 我们已检查架构是否可以访问该过程,并且它在主模式中定义。 We also have tried by creating public synonym for this package. 我们也试过为这个包创建公共同义词。 Still not working.. 还是行不通..
The title of your question is misleading. 你的问题的标题是误导性的。 table of <TYPE>
and table of <TYPE> index by <TYPE>
are two very different data types. table of <TYPE>
table of <TYPE> index by <TYPE>
是两种截然不同的数据类型。 First is called nested table and second is called associative array in Oracle (PL/)SQL parlance. 第一个称为嵌套表 ,第二个在Oracle(PL /)SQL术语中称为关联数组 。
The main problems are that: 主要问题是:
The first issue is addressed eg in How to return an array from Java to PL/SQL? 第一个问题在例如如何将数组从Java返回到PL / SQL中得到解决? (the issue is the same even the call direction is different). (即使呼叫方向不同,问题也是一样的)。
Further reading: 进一步阅读:
create type
. 数据库SQL语言参考create type
。 create type
statement Database PL / SQL语言参考create type
语句 I was able to map a type table of varchar2 to java as follows: 我能够将varchar2的类型表映射到java,如下所示:
Create a new type outside of any PLSQL package and grant necessary permissions. 在任何PLSQL包之外创建一个新类型并授予必要的权限。
CREATE OR REPLACE TYPE STRARRAY AS TABLE OF VARCHAR2 (100); / GRANT all ON MYSCHEMA.STRARRAY TO MYUSER1; / commit;
Create a PLSQL function that accepts/returns the strarray. 创建一个接受/返回strarray的PLSQL函数。 This was declared in the package specification and written in full in the package body. 这是在包规范中声明的,并在包体中完整写入。 Although I declared the array to be IN OUT, in my implementation I only actually use the output from the PLSQL call. 虽然我声明数组是IN OUT,但在我的实现中我实际上只使用了PLSQL调用的输出。
PROCEDURE getArr(arr_var IN OUT strarray) IS counter NUMBER := 1; BEGIN arr_var := new strarray(); WHILE counter <= 10 LOOP arr_var.extend(); arr_var(counter) := 'my data string'; END LOOP; END getArr;
Call the procedure in java. 在java中调用该过程。 In this example the variable conn is of data type Connection and has already been initialized. 在此示例中,变量conn的数据类型为Connection,并且已经初始化。 I am running a jdbc thin client against an Oracle database. 我正在针对Oracle数据库运行jdbc瘦客户端。
CallableStatement proc = null; String sql = "{ call myPackage.getArr(?) }"; try{ proc = conn.prepareCall(sql); proc.registerOutParameter(1, OracleTypes.Array, "MYSCHEMA.STRARRAY"); proc.execute(); Array arrOut = proc.getArray(1); for (int num=0; num<10; num++){ System.out.println(arrOut[num]); }finally{ proc.close(); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.