使用simpleJdbcCall返回结果集-错误的SQL语法错误

时间:2018-06-29 16:28:09

标签: spring stored-procedures spring-jdbc

我目前正在测试spring框架,作为处理我们连接的一种新方法。我正在测试对从simpleJdbcCall返回REF游标的函数的调用。我正在运行的单元测试不断抛出BadSqlGrammarException,我不确定这个问题是从哪里来的,因为我是春季新手。

代码如下:

@Autowired
private SimpleJdbcCall simpleJdbcCall;
private final String schema_name = "xxlt";
private final String procedure_catalog = "xxlt_bpg_std_width_pkg";
private final String procedure_name    = "get_std_rods";

public List<StandardRods> getDefaultRodMatAndColor(String series, String style, String material, String color)
{
    simpleJdbcCall.withSchemaName(schema_name).withCatalogName(procedure_catalog).withProcedureName(procedure_name).useInParameterNames("p_series_ind", "p_style_ind", "p_material_ind", "p_color_ind")
    .returningResultSet("lref", BeanPropertyRowMapper.newInstance(StandardRods.class));

    MapSqlParameterSource paramMap = new MapSqlParameterSource();

    paramMap.addValue("p_series_ind", series, Types.VARCHAR);
    paramMap.addValue("p_style_ind", style, Types.VARCHAR);
    paramMap.addValue("p_material_ind", material, Types.VARCHAR);
    paramMap.addValue("p_color_ind", color, Types.VARCHAR);
    Map m = simpleJdbcCall.execute(paramMap);
    return (List) m.get("lref");

程序:

FUNCTION get_std_rods (p_series_ind IN varchar2, p_style_ind IN varchar2, p_material_ind IN varchar2, p_color_ind IN varchar2)
return SYS_REFCURSOR IS lref SYS_REFCURSOR;
BEGIN
  OPEN lref FOR
    SELECT bbv.default_rod_mat, bbv.default_rod_color
    FROM xxlt.xxlt_bpg_belt_val bbv
    WHERE bbv.series_ind = p_series_ind AND
          bbv.belt_style_ind = p_style_ind AND
          bbv.material_ind = p_material_ind AND
          bbv.color_ind = p_color_ind;
  RETURN lr

错误:

PLS-00306: wrong number or types of arguments in call to 'GET_STD_RODS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

1 个答案:

答案 0 :(得分:0)

您需要在语句中的参数前面加一个冒号,以便系统知道在何处输入您在paramMap中定义的值:

FUNCTION get_std_rods (:p_series_ind IN varchar2, :p_style_ind IN varchar2, 
p_material_ind IN varchar2, :p_color_ind IN varchar2)
return SYS_REFCURSOR IS lref SYS_REFCURSOR;
BEGIN
OPEN lref FOR
SELECT bbv.default_rod_mat, bbv.default_rod_color
FROM xxlt.xxlt_bpg_belt_val bbv
WHERE bbv.series_ind = :p_series_ind AND
      bbv.belt_style_ind = :p_style_ind AND
      bbv.material_ind = :p_material_ind AND
      bbv.color_ind = :p_color_ind;
RETURN lr