[英]Caused by: java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'PR_SP_FAHMI'
I have java file which use to execute Store Procedure by using SimpleJdbc like in the below code:我有 java 文件,该文件用于使用 SimpleJdbc 执行存储过程,如下面的代码:
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {SQLException.class, Exception.class })
public void executeSPForInsertData(DataSource ds,String procedureName,Map<String, Object> inputParameter){
//PARAMS.PKG_PARA_UPLD_VAL.PR_SP_FAHMI
String[] inParam = inputParameter.keySet().toArray(new String[0]);
SqlParameter[] in = new SqlParameter[inParam.length];
String[] buff = new String[inParam.length * 2];
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(paramsDataSourceBean)
.withProcedureName(procedureName)
.withoutProcedureColumnMetaDataAccess()
.useInParameterNames(buff).declareParameters(in);
String[] path = procedureName.split(".");
if (path.length >= 2) {
jdbcCall.withSchemaName(path[0]);
jdbcCall.withCatalogName(path[1]);
jdbcCall.withProcedureName(path[2]);
}
Map<String,Object> outputParameter = jdbcCall.execute(inputParameter);
}
and this is my stored procedure这是我的存储过程
PROCEDURE PR_SP_FAHMI (P_T_TABLE_UPLD_EXCEL IN PARAMS.EXCEL)
is
P_LOGID VARCHAR2(255);
BEGIN
BEGIN
INSERT INTO PARAMS.EMPTY
SELECT
C.PARA_OBJT_GROUP ,
C.PARA_OBJT_CODE ,
C.PARA_PROD_MATRIX_ID ,
C.PARA_PROD_CHANNEL_ID ,
C.PARA_PROD_SALES_GROUP_ID ,
C.PARA_CUST_GROUP ,
C.PARA_SLS_THROUGH_ID ,
C.ACTIVE
FROM TABLE(P_T_TABLE_UPLD_EXCEL) C;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001, 'ERROR-' || SQLERRM);
END;
END PR_SP_FAHMI;
this is declaration type excel这是声明类型 excel
CREATE OR REPLACE TYPE EXCEL AS TABLE OF PARAMS.T_OBJECT_FROM_EXCEL
and this is declaration type T_OBJECT_FROM_EXCEL这是声明类型 T_OBJECT_FROM_EXCEL
CREATE OR REPLACE TYPE "T_OBJECT_FROM_EXCEL" FORCE AS OBJECT (
para_objt_group VARCHAR2(3),
para_objt_code VARCHAR2(3),
para_prod_matrix_id VARCHAR2(5),
para_prod_channel_id VARCHAR2(3),
para_prod_sales_group_id VARCHAR2(5),
para_cust_group VARCHAR2(3),
para_sls_through_id VARCHAR2(2),
active NUMBER(1)
)
When i run the code, i have error this当我运行代码时,我有这个错误
Caused by: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PR_SP_FAHMI'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I have search in internet to solve this issue by looking similliar error but still can't solve my problem.我在互联网上搜索通过查看类似错误来解决这个问题,但仍然无法解决我的问题。
To use Spring to call an Oracle stored procedure that takes a parameter whose type is a table of an object, there are a couple of things that need to be done.要使用 Spring 调用 Oracle 存储过程,该存储过程采用类型为 object 表的参数的参数,需要做几件事。
Firstly, you need to create an Java class that corresponds to the Oracle object type T_OBJECT_FROM_EXCEL
. Firstly, you need to create an Java class that corresponds to the Oracle object type T_OBJECT_FROM_EXCEL
. It needs to implement the SQLData interface.它需要实现SQLData接口。 It will look something like the following (please feel free to change the field names as appropriate):它将如下所示(请随意更改字段名称):
import java.sql.SQLData;
import java.sql.SQLException;
import java.sql.SQLInput;
import java.sql.SQLOutput;
public class ExcelRow implements SQLData {
private String objectGroup;
private String objectCode;
private String prodMatrixId;
private String prodChannelId;
private String prodSalesGroupId;
private String prodCustGroup;
private String slsThroughId;
private boolean active;
// ... constructor, getters and setters omitted ...
@Override
public String getSQLTypeName() {
return "PARAMS.T_OBJECT_FROM_EXCEL";
}
@Override
public void readSQL(SQLInput sqlInput, String typeName) throws SQLException {
throw new SQLException("This has not been implemented");
}
@Override
public void writeSQL(SQLOutput sqlOutput) throws SQLException {
sqlOutput.writeString(this.objectGroup);
sqlOutput.writeString(this.objectCode);
sqlOutput.writeString(this.prodMatrixId);
sqlOutput.writeString(this.prodChannelId);
sqlOutput.writeString(this.prodSalesGroupId);
sqlOutput.writeString(this.prodCustGroup);
sqlOutput.writeString(this.slsThroughId);
sqlOutput.writeInt(this.active ? 1 : 0);
}
}
The SQLData interface has three methods, getSQLTypeName()
, readSQL()
and writeSQL()
. SQLData 接口具有三个方法, getSQLTypeName()
、 readSQL()
和writeSQL()
。 getSQLTypeName()
returns the name of the Oracle type we are mapping to, and writeSQL()
writes the data in an ExcelRow
object to the given output object sqlOutput
. getSQLTypeName()
returns the name of the Oracle type we are mapping to, and writeSQL()
writes the data in an ExcelRow
object to the given output object sqlOutput
. The order of the fields that we write must match the order they are declared in T_OBJECT_FROM_EXCEL
.我们写入的字段的顺序必须与它们在T_OBJECT_FROM_EXCEL
中声明的顺序相匹配。 readSQL()
is used to convert a T_OBJECT_FROM_EXCEL
object returned from the database into an ExcelRow
, but we're only interested in sending values to the database, not receiving them from the database, so for brevity I've just implemented it to throw an exception. readSQL()
用于将从数据库返回的T_OBJECT_FROM_EXCEL
object 转换为ExcelRow
,但我们只对将值发送到数据库感兴趣,而不是从数据库接收它们,因此为简洁起见,我刚刚实现它以抛出一个例外。
Secondly, you need to adjust the code that calls the stored procedure.其次,您需要调整调用存储过程的代码。 Your method executeSPForInsertData
seems to be somewhat generic in that it takes a stored procedure and an arbitrary map of parameters.您的方法executeSPForInsertData
似乎有些通用,因为它需要一个存储过程和任意 map 参数。 Because of the table type parameter, this stored procedure is a little awkward to call in a generic way, so we'll write a method intended specifically for this one stored-procedure call:由于 table 类型参数,这个存储过程以通用方式调用有点尴尬,所以我们将编写一个专门用于这个存储过程调用的方法:
public void executeSPForInsertData(DataSource ds, ExcelRow[] excelRows){
String parameterName = "P_T_TABLE_UPLD_EXCEL";
SqlParameter[] parameterTypes = { new SqlParameter(parameterName, OracleTypes.ARRAY, "PARAMS.EXCEL") };
Map<String, Object> parameters =
Collections.singletonMap(parameterName, new SqlArrayValue<>(excelRows));
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(ds)
.withSchemaName("PARAMS")
.withCatalogName("PKG_PARA_UPLD_VAL")
.withProcedureName("PR_SP_FAHMI")
.withoutProcedureColumnMetaDataAccess()
.declareParameters(parameterTypes);
jdbcCall.execute(parameters);
}
We start by declaring the parameter types: there's one parameter and it's an array whose Oracle type is EXCEL
in the PARAMS
schema.我们首先声明参数类型:有一个参数,它是一个数组,其 Oracle 类型在PARAMS
模式中为EXCEL
。 Then we declare the parameter values, ussing a SqlArrayValue
to wrap the array of ExcelRow
s that we pass in. Finally we set up the stored procedure call and then call it.然后我们声明参数值,使用SqlArrayValue
来包装我们传入的ExcelRow
数组。最后我们设置存储过程调用,然后调用它。 As the parameter name is used twice, I put it in a local variable.由于参数名称被使用了两次,我把它放在一个局部变量中。
I gave this a quick test against an Oracle 18c XE database and it worked, in that I could call this stored procedure and have it write data to the database.我对 Oracle 18c XE 数据库进行了快速测试,它工作正常,因为我可以调用这个存储过程并将数据写入数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.