使用ORACLE 中ROWNUM方法实现数据库分批获取
作者:互联网
ROWNUM能够对查询结果进行编号,之后选择合适区间内容进行返回即可
String sql="select * from ("; sql+="select ROWNUM AS rowno, t.* from "+datatbname+" t where ("+column.get(0)+" like '%"+key+"%'"; for(int i=1;i<column.size();i++){ sql+=" or "+column.get(i)+" like '%"+key+"%'" ; } sql+=") and ROWNUM <= "+maxnum+" ORDER BY years DESC) table_alias WHERE table_alias.rowno > "+minnum;
这样可以获取到最大最小区间内的数据,减少查询时间。
select * from (select ROWNUM AS rowno, t.* from DATA_JGJB_QC t where (DWYZBM like '%河北%' or DWJB like '%河北%') and ROWNUM <= 10 ORDER BY years DESC) table_alias WHERE table_alias.rowno > 0
上边的sql语句可以获取到0-10条数据。需要注意与or连用时要加括号。
也可参考https://blog.csdn.net/xiha_zhu/article/details/79690259
标签:rowno,like,分批,sql,ORACLE,ROWNUM,where,select 来源: https://www.cnblogs.com/lixv2018/p/14496515.html