У меня возникли трудности с вызовом хранимой функции oracle, которая возвращает значение типа таблицы с использованием Mybatis в Spring Tool Suite. Пожалуйста, просмотрите мой код ниже и ответьте мне. Благодарю.Как вызвать функцию oracle, которая возвращает тип таблицы с использованием 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;
/
Я могу получить строки результатов успешно в SQL-разработчике Oracle, как показано ниже.
select *
from table(recommend_func(38));
Mapper.xml весной
<select id="getRecommedList" parameterType="org.ktl.domain.ConfidenceVO"
statementType="CALLABLE" >
{CALL RECOMMEND_FUNC
(
#{startdata, mode=IN, jdbcType=VARCHAR}
)
}
</select>
Java Bean - (. Газопоглотитель & сеттер & метод 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)
}
ДАО код
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.springframewor[email protected]51081592] to prepare test instance [[email protected]]
java.lang.IllegalStateException: Failed to load ApplicationContext
This is the end. plz help me.
Благодаря вашему ответу. Я решил проблему, добавив дополнительную таблицу (tbl_recommend) и модифицирующую функцию в процедуру. и я могу вызвать хранимую процедуру oracle с использованием mybatis, как показано ниже. <вставить ID = "insertRecommedList" statementType = "отзывной"> \t \t \t ВЫЗОВ recommend_proc (# {startdata}) Во всяком случае действительно спасибо. – wjheo