roacle分页查询语句

select a.* from (select t.*,rownum rownum_  from (select *   from ttbrenwu  where tsfsign = '0'and  tsfzdr='100001'   order by tsfzycd desc ,tsfstarttime desc) t where  rownum<6  )a where   rownum_>=2 

 roacle分页查询语句,上面的嵌套了3层,实现了排序分页。

 

Oracle采用嵌套3层的查询语句结合rownum来实现分页,这在Oracle上是最快的方式,如果只是一层或者两层的查询语句的rownum不能支持order by。

 

下面是一个生成Oracle分页sql语句的方法:

  public String getLimitString(String sql) { 
  StringBuffer pagingSelect = new StringBuffer(100); 
  pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( "); 
  pagingSelect.append(sql); 
  pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?"); 
  return pagingSelect.toString(); 
  } 

 

你可能感兴趣的:(oracle,sql)