如何从 MyBatis 将 CURSOR 作为 Oracle 函数参数传递

我们使用MyBatis进行ORM。我需要调用一个Oracle函数,它将游标作为参数。如果MyBatis可以将Java对象映射到游标,那将是理想的,但我怀疑这是否可能。

任何想法如何做到这一点?

请注意,我知道如何将从函数返回的游标映射到Java对象。另一种方式是问题所在。


冉冉说
浏览 198回答 1
1回答

守着一只汪

似乎唯一的解决方案是创建一个块,声明一个游标并将其手动传递给函数:<select id="..." parameterType="..." statementType="CALLABLE">&nbsp; &nbsp; declare&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; my_cursor SYS_REFCURSOR;&nbsp; &nbsp; begin&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OPEN my_cursor FOR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <foreach item="item" collection="..." separator=" union all ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT #{item.key} as key, ... FROM dual&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </foreach> ;&nbsp; &nbsp; &nbsp; &nbsp; #{result,jdbcType=CURSOR,mode=OUT,resultMap=...,javaType=java.sql.ResultSet} := our_function(my_cursor => my_cursor);&nbsp; &nbsp; end;</select>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java