Loading

使用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

posted @ 2021-03-07 21:27  李旭2018  阅读(1891)  评论(0编辑  收藏  举报