繁体   English   中英

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

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

我的Oracle数据库中有一个名为GET_ACS_SERVER_AUTH_METHOD_REP

这是我在数据库中执行函数调用的方式:

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";
    }

不幸的是,这不起作用,并返回以下错误:

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

我问过我们的DBA,也许我这边缺少一些权限,但是他说不。

我也读到,当oracle是12版时,oracle / spring有一些错误。

也许有人遇到类似问题并设法解决了?

谢谢!

如果这是您的功能定义

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

代码应如下所示。

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

原来,我的DataSource bean是通过错误的db凭据传递的,该DataSource bean传递到了具有在数据库中调用该函数的方法的类的构造函数中。 我有多个数据源,必须使用@Qualifier批注定义正确的数据源。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM