我在调用oracle存储函数时遇到了困难,它在Spring Tool Suite中使用Mybatis返回表类型值。请查看下面的代码并回答我。谢谢。
首先,这是我在Oracle sql开发人员中的代码。
create or replace TYPE recommend_type as object
(
pno number,
productthumimage varchar2(500),
confidence number
);
/
create or replace TYPE recommend_table
as table of recommend_type;
/
create or replace function recommend_func
(p_startdata IN varchar2)
return recommend_table
is
r_type recommend_table := recommend_table();
v_conf tbl_confidence%rowtype;
cnt number;
v_pno tbl_product.pno%type;
v_productthumimage tbl_product.productthumimage%type;
v_confidence tbl_confidence.confidence%type;
CURSOR recommendcursor is
select *
from tbl_confidence
where STARTDATA = p_startdata;
BEGIN
open recommendcursor;
cnt := 1;
loop
fetch recommendcursor into v_conf.startdata, v_conf.enddata, v_conf.confidence;
exit when recommendcursor%NOTFOUND;
select pno, productthumimage into v_pno, v_productthumimage
from tbl_product
where PNO = v_conf.enddata;
v_confidence := v_conf.confidence;
r_type.extend;
r_type(cnt) := recommend_type(v_pno, v_productthumimage, v_confidence);
cnt := cnt+1;
end loop;
return r_type;
end;
/
我可以在Oracle sql developer中成功获得结果行,如下所示。
select *
from table(recommend_func(38));
Spring中的Mapper.xml
<select id="getRecommedList" parameterType="org.ktl.domain.ConfidenceVO"
statementType="CALLABLE" >
{CALL RECOMMEND_FUNC
(
#{startdata, mode=IN, jdbcType=VARCHAR}
)
}
</select>
Java bean - 用于in参数和表类型的返回值 (跳过getter&amp; setter&amp; toString方法。)
public class ConfidenceVO {
private String startdata;
private String enddata;
private Double confidence;
( ... getter & setter )
}
public class RecommendVO {
Integer pno;
String productthumimage;
Double confidence;
( ... getter & setter )
}
DAO代码
public List<RecommendVO> getRecommedList(ConfidenceVO confidenceVO) throws Exception {
// TODO Auto-generated method stub
return session.selectList(namespace+".getRecommedList", confidenceVO);
}
junit测试代码
@Test
public void getRecommedListTest() throws Exception {
ConfidenceVO cVO = new ConfidenceVO();
cVO.setStartdata("38");
System.out.println(dao.getRecommedList(cVO));
}//
错误文字
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@51081592] to prepare test instance [org.ktl.test.AprioriDAOTest@623e088f]
java.lang.IllegalStateException: Failed to load ApplicationContext
This is the end. plz help me.
答案 0 :(得分:0)
我不知道java,但我猜测问题是你正在尝试提交一个函数调用。您应该只是执行一个SQL语句。您在SQLDeveloper中使用的相同SELECT语句。 表函数作为查询调用,而不是作为函数调用。