简体   繁体   English

春季:JdbcTemplate尝试调用存储的db函数时抛出PLS-00201

[英]Spring: JdbcTemplate throws a PLS-00201 while trying to call a stored db function

I have a function inside our oracle database named GET_ACS_SERVER_AUTH_METHOD_REP . 我的Oracle数据库中有一个名为GET_ACS_SERVER_AUTH_METHOD_REP

This is how I perform the call of the function in the database: 这是我在数据库中执行函数调用的方式:

public String getAuthReport () throws SQLException {
        final Connection connection = jdbcTemplate.getDataSource().getConnection();

        List <SqlParameter> declaredParameters = new ArrayList <SqlParameter>();
        declaredParameters.add(new SqlParameter("start_d", Types.DATE));
        declaredParameters.add(new SqlParameter("end_d", Types.DATE));
        declaredParameters.add(new SqlOutParameter("return", Types.CLOB));

        Map <String, Object> resultMap = jdbcTemplate.call(new CallableStatementCreator() {
            @Override
            public CallableStatement createCallableStatement (Connection con) throws SQLException {
                CallableStatement callableStatement = connection.prepareCall("{call GET_SERVER_AUTH_METHOD_REP(?, ?, ?)}");
                callableStatement.setDate(1, java.sql.Date.valueOf("2016-01-01"));
                callableStatement.setDate(2, java.sql.Date.valueOf("2017-06-30"));
                callableStatement.registerOutParameter(3, Types.CLOB);
                return callableStatement;
            }
        }, declaredParameters);
        return "success";
    }

This unfortunately doesn't work and returns this error: 不幸的是,这不起作用,并返回以下错误:

Caused by: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'GET_ACS_SERVER_AUTH_METHOD_REP' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

I've asked our DBA if maybe some permissions are missing on my side, but he said no. 我问过我们的DBA,也许我这边缺少一些权限,但是他说不。

Also I've read that there are some bugs with oracle/spring when oracle is version 12. 我也读到,当oracle是12版时,oracle / spring有一些错误。

Maybe somebody encountered something similar and managed to fix it? 也许有人遇到类似问题并设法解决了?

Thanks! 谢谢!

If this is definition of your function 如果这是您的功能定义

create or replace FUNCTION get_server_auth_method_rep(start_d DATE, end_d DATE) return CLOB 

Code should look like this. 代码应如下所示。

CallableStatement callableStatement = con.prepareCall("{? = call GET_SERVER_AUTH_METHOD_REP(?,?)}"); 
callableStatement.registerOutParameter(1, Types.CLOB);
callableStatement.setDate(2, java.sql.Date.valueOf("2016-01-01"));
callableStatement.setDate(3, java.sql.Date.valueOf("2017-06-30"));

Turned out that my DataSource bean which was passed into the constructor of the class that had the method to call the function in the database was passed with wrong db credentials. 原来,我的DataSource bean是通过错误的db凭据传递的,该DataSource bean传递到了具有在数据库中调用该函数的方法的类的构造函数中。 I had multiple DataSources and I had to define the correct one to be passed in by using the @Qualifier annotation. 我有多个数据源,必须使用@Qualifier批注定义正确的数据源。

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

相关问题 PLS-00201:必须声明标识符&#39;GETALLNAMES&#39; - PLS-00201: identifier 'GETALLNAMES' must be declared Spring Data JPA 应用调用 Oracle 包程序出现 PLS-00201 错误 - Spring Data JPA app calling Oracle package procedure rises PLS-00201 error 使用Spring JdbcTemplate中的调用来调用存储的函数 - Calling stored function using call in Spring JdbcTemplate 从Java调用执行PLSQL时的PLS-00201 - PLS-00201 when calling executing PLSQL from java PLS-00201:必须声明标识符“DBMS_SODA_ADMIN.DESCRIBE_COLLECTION” - PLS-00201: identifier 'DBMS_SODA_ADMIN.DESCRIBE_COLLECTION' must be declared 尝试使用Spring JdbcTemplate从Java访问OS400 / DB2存储过程输出参数 - Trying to access OS400/DB2 Stored Procedure Output Parameters from Java with Spring JdbcTemplate 尝试使用Spring JdbcTemplate从Java访问AS400 / DB2存储过程 - Trying to access AS400/DB2 stored procedure from Java with Spring JdbcTemplate 如何使用JdbcTemplate在spring mvc中对存储过程或函数进行简单调用 - How to make a simple call to a stored procedure or function in spring mvc using JdbcTemplate Spring JdbcTemplate 在调用 SQLserver 存储过程时非常慢 - Spring JdbcTemplate is extremely slow when call SQLserver Stored procedure 如何使用 JdbcTemplate 从 Spring 创建存储的 function? - How to create stored function from Spring using JdbcTemplate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM