设置参数时出错

时间:2014-06-26 09:00:14

标签: sql oracle plsql mybatis callable

我正在尝试用MyBatis调用一个程序。

这是程序签名:

PROCEDURE pr_start(io_calc    IN OUT TYPE_CALC,
                   in_restart BOOLEAN DEFAULT TRUE,
                   in_user    VARCHAR2 DEFAULT NULL);

它位于名为PACKAGE_PP的包中。

这是TYPE_CALC的声明方式:

CREATE OR REPLACE TYPE TYPE_CALC AS OBJECT (
    modelField   VARCHAR2(5 CHAR),
    sysField     VARCHAR2(5 CHAR),
    hexField     VARCHAR2(5 CHAR)
);

这是我的XML映射:

<select id="pr_start" 
    statementType="CALLABLE" parameterType="map">
    {
        exec PACKAGE_PP.pr_start(
            #{io_calc,mode=INOUT,jdbcType=STRUCT,jdbcTypeName=TYPE_CALC},
            #{in_restart,mode=IN,jdbcType=BOOLEAN,jdbcTypeName=BOOLEAN},
            #{in_user,mode=IN,jdbcType=VARCHAR,jdbcTypeName=VARCHAR2}
        )
    }
</select>

p.s。我也尝试使用call代替exec,它会产生相同的错误)

我的java mapper:

public interface PackagePPMapper {
    Object pr_start(Map<String, Object> param);
}

这就是我所说的:

Object[] typeCalcArr = new Object[]{"A", "s", "0xD"};

WebSphereNativeJdbcExtractor wsn = new WebSphereNativeJdbcExtractor();
Connection connection = wsn.getNativeConnection(session.getConnection()); //session is a SqlSession (properly initialized)
StructDescriptor descriptor = StructDescriptor.createDescriptor("TYPE_CALC", connection);
STRUCT typeCalc = new STRUCT(descriptor, connection, typeCalcArr);

Map<String, Object> parametersMap = new HashMap<String, Object>();
parametersMap.put("io_calc", typeCalc);
parametersMap.put("in_restart", restart);
parametersMap.put("in_user", user);

getMapper(session).pr_start(parametersMap);

堆栈跟踪:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: Non supported SQL92 token at position: 6
### The error may exist in com/jsfproj/mybatis/xmlmapper/PackagePPMapper.xml
### The error may involve com.jsfproj.mybatis.PackagePPMapper.pr_start-Inline
### The error occurred while setting parameters
### SQL: {    exec PACKAGE_PP.pr_start(     ?,     ?,     ?    )   }
### Cause: java.sql.SQLException: Non supported SQL92 token at position: 6

我错过了什么?应该以其他方式调用程序吗?

1 个答案:

答案 0 :(得分:0)

删除周围的大括号stop JDBC driver from trying to interpret query as SQL92-compatible query

<select id="pr_start" statementType="CALLABLE" parameterType="map">
  call PACKAGE_PP.pr_start(
            #{io_calc,mode=INOUT,jdbcType=STRUCT,jdbcTypeName=TYPE_CALC},
            #{in_restart,mode=IN,jdbcType=BOOLEAN,jdbcTypeName=BOOLEAN},
            #{in_user,mode=IN,jdbcType=VARCHAR,jdbcTypeName=VARCHAR2}
        )
</select>

也可以使用本机Oracle语法:

<select id="pr_start" statementType="CALLABLE" parameterType="map">
  begin
    PACKAGE_PP.pr_start(
      #{io_calc,mode=INOUT,jdbcType=STRUCT,jdbcTypeName=TYPE_CALC},
      #{in_restart,mode=IN,jdbcType=BOOLEAN,jdbcTypeName=BOOLEAN},
      #{in_user,mode=IN,jdbcType=VARCHAR,jdbcTypeName=VARCHAR2}
    );
  end;
</select>