sql中幾種批量foreach的寫法記錄
1,條件語句中使用or連線的遍歷
<foreach collection="propertyLevelSectionList" item="itr" index="index" separator=" or " open=" and(" close=")">
( a.PROPERTY_LEVEL_ONE = #{itr.propertyLevelOne} and a.PROPERTY_LEVEL_TWO = #{itr.propertyLevelTwo} )
</foreach>
2,insert插入語句時foreach寫法
<insert>
insert into 表明(
欄位名
)(
<foreach collection="list" item="item" index="index" separator="UNION ALL">
select
欄位
from
dual
</foreach>
)
</insert>
3,where條件中某個欄位在某一範圍collection="areaidSet"(類中集合的名稱)
where 欄位名 in
<foreach item="item" index="index" collection="areaidSet" open="(" separator="," close=")">
#{item}
</foreach>
4,update:資料更新時的foreach寫法
<update>
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
</foreach
</update>