当前位置: 代码迷 >> 综合 >> sql中几种批量foreach的写法记录
  详细解决方案

sql中几种批量foreach的写法记录

热度:51   发布时间:2023-09-18 20:30:51.0


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>