下午好。我试图调用一个函数,该函数的参数由一个集合User-Defined Type定义。 (据我所知)参数定义为集合(即类型定义为表)时会出现问题。我是Oracle新手,但是通过jdbc与其他数据库一起使用
Oracle(12c):
type TParameterValue is record(
Value varchar2(500),
Name varchar2(500)
);
type TParameter is record(
Code varchar2(100),
Value TParameterValue
);
type TParameters is table of TParameter;
function ChangeEquipmentRequest(
pParameters in TParameters
) return TChangeEquipmentResponse;
Java(ojdbc8 12.2):
connection = ...
OracleCallableStatement statement = (OracleCallableStatement) connection.prepareCall(String.join("",
"{?= call ",
config.getDbPrefix(),
".CHANGEEQUIPMENTREQUEST(?)}"));
statement.registerOutParameter(1, Types.STRUCT,config.getDbPrefix().concat(".TCHANGEEQUIPMENTRESPONSE"));
Struct structValue = connection.createStruct(
config.getDbPrefix().concat(".TPARAMETERVALUE"),
new Object[]{"1","2"}
);
Struct structParam = connection.createStruct(
config.getDbPrefix().concat(".TPARAMETER"),
new Object[]{"code",structValue}
);
Object[] objects1 = new Object[]{structParam};
Struct structParams = (Struct) connection.createStruct(
config.getDbPrefix().concat(".TPARAMETERS"),
objects1
);
statement.setObject(2, structParams, Types.STRUCT);
当我尝试为类型 TPARAMETERS 创建结构时,出现问题
java.sql.SQLException: Fail to construct descriptor: Invalid arguments
此后,我搜索了oracle中的集合正在映射为数组
v2与数组:
oracle.sql.ARRAY arrayParameters = (ARRAY) ((oracle.jdbc.OracleConnection) connection).createOracleArray(
config.getDbPrefix().concat(".TPARAMETERS"),
new Object[]{structParam,structParam,structParam,structParam}
);
statement.setObject(2, arrayParameters, Types.ARRAY);
我得到:
PLS-00306: Invalid number or types of arguments when accessing 'CHANGEEQUIPMENTREQUEST'
据我了解,这是因为Types.ARRAY
所以我仍然必须通过Types.STRUCT
注意:我已经使用结构描述了定义为 is record 的类型,并且可以正常工作, 但是如果类型定义为一个集合(是XXX表),我就必须做其他事情
谢谢,有什么想法吗?