首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

oracle分页语句。该如何处理

2012-09-11 
oracle分页语句。String sql select * from (select rownum rn,news.* from (select * from News where

oracle分页语句。
String sql = "select * from (select rownum rn,news.* from (select * from News where title = "+"'"+title+"' or class="+"'"+classs+"'" + "order by ID ) news) where rn <=" + rowBegin;

我怎么分页查询5个一页 sql语句怎么写?

[解决办法]
select x.* from (select z.*,rownum r from zzg z) x where x.r>&num*5 and x.r<(&num+1)*5
这样试试
[解决办法]
select * from (
select id , pid , rootid ,title ,con ,pdate ,isleaf, rownum r ,virtualDatefrom
(select * from article where pid = 0 order by pdate desc)
)where r >= 4 and r <= 8;类似这样的
article表如下:
create table article
(
 id number primary key,//id号
 pid number,//父节点
 rootid number,//根节点
 title varchar2(256),//标题
 con varchar2(1000),//内容
 pdate date,//时间
 isleaf number --1代表非叶子,0代表叶子
virtualDate date default Sysdate--用来flat中的排序,当有人回复主题帖时其值会改变,只有root节点才会有实在的virtualDate
)
[解决办法]
select * from (select e.*,rownum as rn from scott.emp e where rownum<=(nowPage*pageSize)) where rn>(nowPage-1)*pageSize;

//nowPage 当前页
//pageSize 每页显示的记录数
[解决办法]

Java code
/**     * 获得分页(该方法暂时不支持sqlserver)     * @param sql 查询数据数量的sql必须是select * from 开头     * @param args 参数列表(可以为null)     * @param pageIndex 当前页数     * @param radix 分页的基数     * @param function 分页的js函数,比如:document.form1.submit()     * @return PageModel     * */    public PageModel getPage(String sql, Object[] args, int pageIndex, int radix, String function) {        args = (null == args ? new Object[] {} : args);        PageModel model = pagination(sql.replace("*", "count(*)"), args, pageIndex, radix, function);         Object[] newArgs = new Object[args.length + 2];        for (int i = 0; i < args.length; i++) {            newArgs[i] = args[i];        }        if (JdbcConfig.DATABASE_ORACLE.equals(jdbcConfig.getDatabaseType())) {            sql = "select * from ( select temp.*, rownum rownumt from (" + sql + ") temp where rownum <= ?) where rownumt > ?";            newArgs[newArgs.length - 2] = model.getStop();            newArgs[newArgs.length - 1] = model.getStart();            model.setList(getDataList(sql, newArgs));        }        if (JdbcConfig.DATABASE_MYSQL.equals(jdbcConfig.getDatabaseType())) {            sql += " limit ?,?";            newArgs[newArgs.length - 2] = model.getStart();            newArgs[newArgs.length - 1] = radix;            model.setList(getDataList(sql, newArgs));        }        return model;    }
[解决办法]
片段代码:
Java code
public PageModel getOrders(LogOrders orders, int pageIndex, int radix) {        String sql = "select * from DECO_LOG_ORDERS where DEPT_NAME = ?";        List<Object> args = new ArrayList<Object>();        args.add(orders.getDeptName());        if (null != orders.getPactCode() && !"".equals(orders.getPactCode())) {            sql += " and PACT_CODE like ?";            args.add("%" + orders.getPactCode() + "%");        }        if (null != orders.getOrderCode() && !"".equals(orders.getOrderCode())) {            sql += " and ORDER_CODE like ?";            args.add("%" + orders.getOrderCode() + "%");        }        sql += " order by ORDERS_ID";        return getPage(sql, args.toArray(), pageIndex, radix, orders.getFunction());    } 

热点排行