I need to return a value from a PL/SQL block in MyBatis.
The PL/SQL block is this:
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 a value, is that I want to be able to get the number of affected rows.
I know I could 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 I must have a method like this in the java mapper:
public void updateAll(Map<String, String> parameters);
I have this instead:
public int updateAll(@Param("params") List<PriorityModel> model);
Is there a way to return that value without having a map?
I think you can't return a value from a procedure call. It's possible set a value in an object like a pojo or a map like your example but, i think if you at the same sql transaction execute a query after the updates like this:
SELECT sql%rowcount FROM DUAL;
You can get the number of affected rows like a ResultSet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.