【问题标题】:Calling stored procedure with @Query results in Exception: wrong number or types of arguments in call to ProcedureName使用 @Query 调用存储过程会导致异常:调用 ProcedureName 时参数的数量或类型错误
【发布时间】:2020-01-30 08:26:32
【问题描述】:

我在调用存储过程时遇到问题

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);

}

我正在使用 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'

【问题讨论】:

    标签: java jpa stored-procedures spring-data-jpa spring-data


    【解决方案1】:

    您已经用三个参数声明了您的存储过程,但您在@Query 注释的 SQL 脚本中只用两个参数调用它。

    一旦修复,您将在下一个问题中运行,因为您的脚本不会返回值。 JPA 不知道从中返回什么,因此 Spring Data JPA 也是如此。我完全不确定您选择的方法是否可以解决此问题。

    对于使用 JPA 调用存储过程,我强烈推荐 declaring them using @NamedStoredProcedureQuery。 然后你可以access that stored procedure using Spring Data JPA

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-30
      • 2011-07-01
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      相关资源
      最近更新 更多