Return value from PL / SQL block

I need to return a value from a PL / SQL block in MyBatis.

PL / SQL block:

DECLARE BEGIN <foreach collection="params" item="param"> UPDATE PRIORITIES SET PRIORITY = #{param.priority} WHERE ID = #{param.id}; </foreach> END 

The reason I need to return the value is because I want to get the number of rows affected.

I know I can do it like this:

 <update id="updateAll" parameterType="map"> { call DECLARE BEGIN <foreach collection="params" item="param"> UPDATE PRIORITIES SET PRIORITY = #{param.priority} WHERE ID = #{param.id}; </foreach> #{affected_rows, jdbcType=DECIMAL, mode=OUT} := sql%rowcount; END } </update> 

But this means that I should have such a method in a java translator:

 public void updateAll(Map<String, String> parameters); 

I have this instead:

 public int updateAll(@Param("params") List<PriorityModel> model); 

Is there any way to return this value without a card?

+5
source share
1 answer

I think you cannot return a value from a procedure call. It is possible to set a value in an object such as pojo or a map similar to your example, but I think if you are executing a query in the same sql transaction after such updates:

 SELECT sql%rowcount FROM DUAL; 

You can get the number of rows affected, for example ResultSet.

0
source

Source: https://habr.com/ru/post/1209762/


All Articles