【Oracle XML 中的 in条件查询】

Oracle in 条件查询
1 foreach 的参数描述

在 mapper 层或 dao 层中,参数是一个 list,所以在 XML 中的 SQL,需要 foreach 放在 in 的条件中进查询。其中 collection 是mapper层或dao的参数,item是list中的对象,index是item对象在list中的索引,open则是 list 以“(”左括号开始,item之间用逗号“,”隔开,以“)”为list结束的标志。

2 代码
select category4_id, category4_name, t1.category3_id, t1.category3_name
from tb_categoryview t1 join(
	select distinct category3_id from tb_select_devicesview
	where category2_id in
		<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
			#{item}
		</foreach>
) t2
on t1.category3_id = t2.category3_id
and materialgroup4_name is not null
and t1.materialgroup3_name is not null
order by category4_id
3 foreach 标签

关键的SQL是:主要是对 foreach 的使用

<foreach collection="list" item="item" index="index" open="(" separator="," close=")">
	#{item}
</foreach>
4 如果 list 的 size 比较小的情况下,或确定的情况
select category4_id, category4_name, t1.category3_id, t1.category3_name
from tb_categoryview t1 join(
	select distinct category3_id from tb_select_devicesview
	where category2_id in ('A01', 'C02', 'B01')
) t2
on t1.category3_id = t2.category3_id
and materialgroup4_name is not null
and t1.materialgroup3_name is not null
order by category4_id

即 list 是确定的,可一一列举的情况。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值