<select id="mapper中的方法名" resultType="返回类型">
select
t.id as id,
t.user_name as username,
t.age as age
from
user t
<where>
<!-- choose when 可以不加,我这里是业务需要 -->
<choose>
<when test="list != null and list.size() > 0">
<!-- 集合不为空时,遍历,下方sepatator中的or,是因为业务需要,你可以根据自己的需求选择分隔符 -->
<foreach collection="list" item="item" index="index" open="(" separator="or" close=")">
(
t.user_name = REGEXP_SUBSTR(#{item}, '[^-]+', 1, 1)
and t.age= REGEXP_SUBSTR(#{item}, '[^-]+', 1, 2)
)
<foreach>
</when>
<otherwise>
<!-- 集合为空时,添加其他条件 -->
1 = 1
</otherwise>
</choose>
</where>
</select>
Java Oracle动态sql字符串切割 split函数类似功能实现
最新推荐文章于 2024-04-03 16:13:15 发布
本文描述了如何在Oracle的mapper接口中,利用REGEXP_SUBSTR函数和foreach遍历,根据传入的参数list(如名字和年龄组成的字符串列表)动态构建SQL查询,以过滤数据库中的用户记录。

最低0.47元/天 解锁文章
1083

被折叠的 条评论
为什么被折叠?



