简体   繁体   English

使用@Query 调用存储过程会导致异常:调用 ProcedureName 时的参数数量或类型错误

[英]Calling stored procedure with @Query results in Exception: wrong number or types of arguments in call to ProcedureName

I have an issue with calling a stored procedure我在调用存储过程时遇到问题

create or replace PROCEDURE TProc1 
                            (i_cob_date IN   DATE,
                             i_location IN   VARCHAR2,
                             o_ret      OUT  VARCHAR2
                            )
AS
BEGIN
 --logic to update a table based on i_cob_date 

    o_ret := '0';
    commit;

END TProc1;
public interface MyRepository extends CrudRepository<MyEntity, Long> {

    @Query(value = "call TProc1(:i_cob_date, :i_location)", nativeQuery = true)
    String markStatus(@Param("i_cob_date")Date cobDate, @Param("i_location")String location);

}

I am using SpringBoot with Spring Data JPA, when i tried to invoke the method I got below error.我将 SpringBoot 与 Spring Data JPA 一起使用,当我尝试调用出现以下错误的方法时。

Could not extract the ResultSet
Caused by: java.sql.SQLException: ORA-06553: PLS-306: wrong number or types of arguments in call to 'TProc1'

You have declared your stored procedure with three parameters, but you are calling it only with two in the SQL script in the @Query annotation.您已经使用三个参数声明了您的存储过程,但在@Query注释的 SQL 脚本中仅使用两个参数来调用它。

Once that is fixed you will run in the next problem, because your script doesn't return a value.一旦修复,您将在下一个问题中运行,因为您的脚本不返回值。 JPA wouldn't know what to return from that and therefore the same is true for Spring Data JPA. JPA 不知道从中返回什么,因此 Spring Data JPA 也是如此。 I'm not at all sure if that can be fixed with the approach you choose.我完全不确定您选择的方法是否可以解决这个问题。

For calling stored procedures with JPA I highly recommend declaring them using @NamedStoredProcedureQuery .对于使用 JPA 调用存储过程,我强烈建议使用@NamedStoredProcedureQuery声明它们 You can then access that stored procedure using Spring Data JPA .然后您可以使用 Spring Data JPA 访问该存储过程

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

相关问题 EclipseLink:调用存储过程的参数数目或类型错误 - EclipseLink: Wrong number or types of arguments calling a Stored Procedure 执行存储过程时,在调用异常时获取错误的数量或参数类型 - Getting wrong number or types of arguments in call to exception while executing stored procedure 在存储过程中插入Blob null时参数数目或类型错误 - Wrong number or type of arguments while inserting Blob null in Stored Procedure 调用“ DROP_QUEUE_TABLE”时参数的数量或类型错误 - wrong number or types of arguments in call to 'DROP_QUEUE_TABLE' 向存储过程/ SQL提供可变数量的参数 - Supplying variable number of arguments to a stored procedure / SQL MyBatis Oracle呼叫PLS-00306:呼叫错误的参数数量或类型错误 - MyBatis Oracle Call PLS-00306: wrong number or types of arguments in call Error 使用存储过程iBATIS进行调用时出现异常 - Exception from call with stored procedure iBATIS PLS-00306:Java中对GET_NEW_EVENTS的调用中参数的数量或类型错误 - PLS-00306: wrong number or types of arguments in call to GET_NEW_EVENTS in Java ORA-06550:第1行,第7列:PLS-00306:错误的数量或调用中的参数类型 - ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call 使用JPA @Query()调用存储过程 - Calling stored procedure using JPA @Query()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM