oracle 动态分页查询的写法

 mapper.xml 文件 :

<!-- 动态查询 一页显示的内容 -->
  <select id="selestPageByFactory" parameterType="java.util.Map" resultMap="BaseResultMap">
    
  select * from (
  select * from(
  select t1.* from(
  select rownum rn ,t.FACTORY_ID,t.FULL_NAME,t.FACTORY_NAME,t.CONTACTS ,t.PHONE,t.MOBILE,
  t.FAX,t.CNOTE,t.INSPECTOR
  from  FACTORY_C t  where 1=1 
  <if test="FULL_NAME!=null and FULL_NAME != '' ">
			and	 t.FULL_NAME like concat(concat('%',#{FULL_NAME}),'%')
		</if>
		<if test="FACTORY_NAME!=null  ">
			and t.FACTORY_NAME like concat(concat('%',#{FACTORY_NAME}),'%')
		</if>
		<if test="CONTACTS!=null  ">
			and t.CONTACTS like concat(concat('%',#{CONTACTS}),'%')
		</if>
		<if test="PHONE!=null ">
			and t.PHONE like concat(concat('%',#{PHONE}),'%')
		</if>
		<if test="MOBILE!=null ">
			and t.MOBILE like concat(concat('%',#{MOBILE}),'%')
		</if>
		<if test="FAX!=null ">
			and t.FAX like  concat(concat('%',#{FAX}),'%')
		</if>
		<if test="CNOTE!=null">
			and t.CNOTE like concat(concat('%',#{CNOTE}),'%')
		</if>
			order by t.factory_id desc
		
  ) t1 where t1.rn   <![CDATA[>=]]> #{start}
  ) t2 where t2.rn   <![CDATA[<=]]> #{end}
  ) t3
 
  </select>
  
  <!-- 查询总条数 -->
  <select id="selectPageCount" parameterType="java.util.Map" resultType="java.lang.Integer" >
   select count(cc.FACTORY_ID) from  FACTORY_C cc where 1=1 
  <if test="FULL_NAME!=null ">
			and	 cc.FULL_NAME like '%'||#{FULL_NAME}||'%'
		</if>
		<if test="FACTORY_NAME!=null  ">
			and cc.FACTORY_NAME like '%'||#{FACTORY_NAME}||'%'
		</if>
		<if test="CONTACTS!=null  ">
			and cc.CONTACTS like '%'||#{CONTACTS}||'%'
		</if>
		<if test="PHONE!=null ">
			and cc.PHONE like '%'||#{PHONE}||'%'
		</if>
		<if test="MOBILE!=null ">
			and cc.MOBILE like '%'||#{MOBILE}||'%'
		</if>
		<if test="FAX!=null ">
			and cc.FAX like '%'||#{FAX}||'%'
		</if>
		<if test="CNOTE!=null">
			and cc.CNOTE like '%'||#{CNOTE}||'%'
		</if>
  		
  </select>
注意 :  oracle 分页  先查询 再分页   

模糊查询的写法 : 
like '%'||#{MOBILE}||'%'   或者   
like  concat(concat('%',#{CNOTE}),'%')  
符号会转义 所以要用 <![CDATA[ ]]> 括起来
例如 >= : <![CDATA[ >=]]>
分页用 : select rownum rn from ....
先查 >= 后查 <= 根据需求查询





 
 
    




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星火染星野

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值