关于oracl的带分页与order by 的查询语句

qisong 2003-10-17 06:58:55
请问那位老兄知道如何用oracl写分页且包含order by 的查询的语句
如我想查出表A中的按A.a 倒序的第N至第M的记录!
急急!谢了!
...全文
66 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanghuazhanghome 2003-10-18
  • 打赏
  • 举报
回复
select * from table A order by A.a desc limit M,N
lynx1111 2003-10-17
  • 打赏
  • 举报
回复
第N至第M的记录:

select * from(select rownum id,aaa,bbb from table1) t where t.id>=n and t.id<=m;
lynx1111 2003-10-17
  • 打赏
  • 举报
回复
<html>
<head>
<%@ page contentType="text/html;charset=gb2312" %>
<title>会员管理</title>
<link rel=stylesheet href="../style.css" type="text/css">
</head>
<body>
<center><p><h4><font color="blue">会员管理</font></h4></p>
<%@ page language="java" import="java.sql.*" %>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:myoracle";
//orcl为你的数据库的SID
String user="test";
String password="123";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//指定行数
int pageLine=3;
int totalRec=0;
int totalSub=0;
int intPage=1;
int i;
if (request.getParameter("page")!=null)
intPage=Integer.parseInt(request.getParameter("page"));

try{
ResultSet countrs;
//取得总记录数
countrs=stmt.executeQuery("select count(*) as cnt from TABLE1 order by aaa desc");
while(countrs.next())
totalRec=countrs.getInt("cnt");
countrs.close();
}
catch(Exception e){
e.printStackTrace();
}
out.println(totalRec);
//取得总页数
int intPageCount=0;
intPageCount = (totalRec+pageLine-1) / pageLine;
%>
<%
ResultSet RS = stmt.executeQuery("select * from TABLE1 order by aaa desc");
String aaa;
String bbb;

%>
<table border='1' cellspacing='0' width='100%' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>
<tr bgcolor='#c8cc98' align='center'>
<td width='8%'>ID</td>
<td width='14%'>会员名</td>
</tr>
<%
if (intPageCount>0)
{
for(i=1;i<=(intPage-1)*pageLine;i++)
RS.next();
for(i=1;i<=pageLine;i++) {
if (RS.next()) {

aaa=RS.getString("aaa");
bbb=RS.getString("bbb");
%>
<tr>
<td width='8%' align='center'><%=aaa%></td>
<td width='14%' align='center'><%=bbb%></td>

</tr>
<%
}
}
RS.close();
}
%>
<!--以下用于分页显示 -->
<%
out.print("<tr>");
if (intPageCount*pageLine<totalRec)
intPageCount++;
if (intPage>intPageCount )
intPage=intPageCount;
if (intPage < 1 )
intPage=1;
out.print("<form method='POST' name=fPageNum action='oracle.jsp'>");
out.print("<p align='left'>>>分页 ");

if (intPage<2)
out.print("<font color='999966'>首页 上一页</font> ");
else{
out.print("<a href='oracle.jsp?page=1'>首页</a> ");
out.print("<a href='oracle.jsp?page=" + (intPage-1) + "'>上一页</a> " );
}


if( intPage-intPageCount>=0 )
out.print("<font color='999966'>下一页 尾页</font>" );
else{

out.print("<a href='oracle.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='oracle.jsp?page=" + intPageCount + "'>尾页</a>");
}

out.print(" 页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 " );
out.print(" 共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 " );
out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");
out.print("页<input class=buttonface type='submit' value='GO' name='cndok'></span></p></form>" );

out.print("</td>");
out.print("</tr>");

%>
</table></p>
<a href="javascript:window.close();">[关闭]</a>
</center>
</body>
</html>
qisong 2003-10-17
  • 打赏
  • 举报
回复
怎么没有高手呀?
qdubit 2003-10-17
  • 打赏
  • 举报
回复
关注!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧