【问题标题】:JdbcTemplate and stored procedure from package Oracle12cDialect来自包 Oracle12cDialect 的 JdbcTemplate 和存储过程
【发布时间】:2020-02-27 17:54:23
【问题描述】:

我正在尝试从包 APP Oracle10g 中调用存储过程“getGlobalParamValue”

org.springframework.boot 版本'2.2.0.RELEASE'

FUNCTION getGlobalParamValue(
        pCode VARCHAR2  
    RETURN INTEGER;

当我在 SQL 开发人员中运行它时,一切正常,我得到了正确的结果

我试过了

1.

    jdbcTemplate.update("BEGIN APP.getGlobalParamValue('base'); END;");

或 2.

    val sjc = new SimpleJdbcCall(jdbcTemplate)
                        .withCatalogName("APP")
                        .withProcedureName("getGlobalParamValue");
    sjc.useInParameterNames("pCode")
                    .withoutProcedureColumnMetaDataAccess()
                    .declareParameters(new SqlOutParameter("p_out", OracleTypes.INTEGER),
                     new SqlParameter("pCode", OracleTypes.VARCHAR));
    SqlParameterSource in = new MapSqlParameterSource()
                    .addValue("pCode", "base");
    sjc.execute(in);

没用

我收到一个错误:

Caused by: org.springframework.jdbc.BadSqlGrammarException:CallableStatementCallback; bad SQL grammar
nested exception is java.sql.SQLException: ORA-06550`

【问题讨论】:

    标签: spring-boot jdbctemplate


    【解决方案1】:

    得到原始类型作为结果对我有用

    val sql = "select APP.getGlobalParamValue('baseAirport') from dual";
    val seq = jdbcTemplate.queryForObject(sql, new Object[] {}, Long.class);
    

    我找到了一个例子 很有趣 https://github.com/spring-projects/spring-integration-samples/tree/master/intermediate/stored-procedures-oracle

    【讨论】:

      【解决方案2】:

      试试这个:

      使用 JdbcTemplate:

       int returnResult = jdbcTemplate.queryForObject("SELECT APP.getGlobalParamValue(?) FROM DUAL", new Object[] {pCode});
      

      使用 EntityManager:

          BigDecimal returnResult = null;
      
          returnResult = (BigDecimal) entityManager.createNativeQuery(
                          "SELECT APP.getGlobalParamValue(:pCode) FROM DUAL" )
                  .setParameter("pCode", yourPCode)
                  .getSingleResult();
      

      【讨论】:

        【解决方案3】:

        我得到了数据集作为结果

        jdbcTemplate.query("select * from table(MYPACKAGE.getrows(21861, 6793, 1829,57464))",(ResultSet rs)->{
            while(rs.next()){
                System.out.println(rs.getInt("ID"));
            }
        });
        

        【讨论】:

          猜你喜欢
          • 2015-11-06
          • 2018-07-26
          • 2016-09-07
          • 2023-03-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-02
          相关资源
          最近更新 更多