Spring JDBC模板。如何获得pl / sql脚本的结果变量 [英] Spring JDBC Template. How can get outcome variables of the pl/sql script

查看:194
本文介绍了Spring JDBC模板。如何获得pl / sql脚本的结果变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NamedParameterJdbcTemplate运行pl / sql脚本。
但我不知道如何获得out变量的值(:id_out )。
提前致谢。

I am using NamedParameterJdbcTemplate for run pl/sql script. But I don't know how can I get the values ​​of out variables (:id_out). Thanks in advance.

String script = "declare 
                   begin 
                     if myFunc(:id_in) is null then 
                        :id_out := 0; 
                     else 
                        :id_out := 1; 
                     end if; 
                   end;";
Map<String,Object> bindVars = new HashMap<String, Object>();
bindVars.put(id_in,1);
bindVars.put(id_out,2);


jdbcTmpl.execute(script, bindVars, new PreparedStatementCallback<Object>() {
    @Override public Object doInPreparedStatement(PreparedStatement cs)
        throws SQLException, DataAccessException {
        cs.execute();
        return null;
                }
       }
       );


推荐答案

我不相信你可以使用NamedParameterJdbcTemplate(或者带有匿名PL / SQL块的JdbcTemplate的任何其他子类,如上所述。您必须将匿名PL / SQL块包装到存储过程或函数中。

I don't believe you can use a NamedParameterJdbcTemplate (or any other subclass of JdbcTemplate) with anonymous PL/SQL blocks such as that above. You'll have to wrap your anonymous PL/SQL block into a stored procedure or function.

Spring旨在跨数据库移植。据我所知,MySQL和SQL Server都没有类似于Oracle的匿名PL / SQL块的概念(尽管我很高兴在这一点上被证明是错误的)。由于此功能不能跨数据库移植,因此Spring不能仅仅支持Oracle。

Spring is intended to be portable across databases. As far as I know, neither MySQL nor SQL Server have a concept analogous to Oracle's anonymous PL/SQL blocks (I'm happy to be proved wrong on this point, though). Since this feature isn't portable across databases, Spring can't really support it for just Oracle.

这篇关于Spring JDBC模板。如何获得pl / sql脚本的结果变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆