欢迎光临
我们一直在努力

如何返回指定行数之间的查询结果?-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

 
如何返回指定行数之间的查询结果?

    如何返回指定行数之间的查询结果,以实现web记录分页,在oracle中有许多的方法,这里仅仅列出了4种,希望能对大家有所帮助,大家可以根据不同需要选择下面的script 

1)select … where rownum < 50 minus select … where rownum < 30  
    这个方法因为用到了minus操作符,所以速度会受影响。  

2) 
select results.* from  
( select t2.*, rownum rownumber from  
( select t.* from mv_table t where order by col1) t2) results  
where results.rownumber between 30 and 50 order by col1 

这个方法是从一个论坛上看到的,没有亲自测试过  

3) 
定义cursor x, 2.fetch x a,b,c; loop …… end loop;  
其中用两个循环变量和一个flag变量,分别表示,当前的记录数,属于第几页的, 及第一页面。  
ps;  
j:=to_number(kafyf);  
i:=1;  
open cx;  
loop fetch cx into col1,col2,col3,col4,col5,col6;  
if cx%notfound then exit; end if;  
    if i>=j then  
htp.tablerowopen;  
htp.tabledata(col1);  
htp.tabledata(col2);  
htp.tabledata(col4);  
htp.tabledata(col5);  
htp.tabledata(col6);  
htp.tabledata(col3);  
htp.tablerowclose;  
i:=i+1;  
if i=j+10 then l:=1; exit; end if;  
else i:=i+1;  
end if;  
end loop;  
close x;  

该方法是名叫‘淼’的网友写的script,他用到了oracle web2kit中的owa_util package。 

4)how can one page forward and backwards through a table? 
externalize rownum by implementing queries like this:  

select …  
from (select rownum rnum, … from …)  
where rnum between :low and :high and rownum <(:high :low + 1);  

    where :low and :high are dynamically generated values depending on which result page the user 
is viewing. typically, they are used to show “next 15 matches”, “previous 15 matches” links at the 
bottom of each page.  

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何返回指定行数之间的查询结果?-数据库专栏,SQL Server
分享到: 更多 (0)