序列_RowNum分页笔记

 
CREATE TABLE SCOTT.S1_Score
(
 ID NUMBER(10),
 Score NUMBER(3),
 Name VARCHAR2(10)
)
 
CREATE TABLE SCOTT.S2_Score
(
 ID NUMBER(10),
 Score NUMBER(3),
 Name VARCHAR2(10)
)
 
CREATE TABLE SCOTT.Y2_Score
(
 ID NUMBER(10),
 Score NUMBER(3),
 Name VARCHAR2(10),
 Descr      VARCHAR2(10)
)
 
insert into S1_Score(ID,Score,Name) values(1,80,'张三')
 
create sequence seq_y2score
        start 1000
 increment by 1
 
select seq_score.nextval from dual
select seq_score.currval from dual
 
insert into S1_Score(ID,Score,Name) values(seq_score.nextval ,80,'张三')
insert into S2_Score(ID,Score,Name) values(seq_score.nextval ,80,'张三')
insert into S2_Score(ID,Score,Name) values(seq_y2score.nextval ,80,'张三')
insert into S2_Score(ID,Score,Name) values(5 ,80,'张三')
 
insert into S2_Score(ID,Score,Name)
    values(seq_score.nextval ,seq_y2score.nextval,'张三')
 

select a.empno, rowid rid,rownum from emp a
select * from emp where rowid='AAAH14AABAAAO+HAAI'
 
select *,rownum from emp
select empno,ename,rownum from emp where ename>='K'
select empno,ename,rownum from emp where ename>='K' order by ename
 
第一页:允许有限制条件
   select * from emp where rownum<=3
    select * from emp where ename>='K' and rownum<=3
 
    //错误,先取一页,在一页中排序
      select * from emp where ename>='K' and rownum<=3 order by ename
      正确,有排序的时候,查询第一页
select a.* from (
select * from emp where ename>='K' order by ename) a
where rownum<=3
 
第2,3,4页:允许有限制条件
  select * from emp where rownum<=6 and rownum>3//错误
select * from emp where rownum=1//正确
select * from emp where rownum=2//错误
select * from emp where rownum>3//错误
 
select * from
(select a.*, rownum rn from emp a where rownum<=9)
where rn>6
 
select * from
(select a.*, rownum rn from emp a where ename>='K' and rownum<=9)
where rn>6
 
//错误,先取一页,在一页中排序
select * from
(select a.*, rownum rn from emp a where ename>='K' and rownum<=9 order by ename)
where rn>6
 

 正确,有排序的时候,查询第2,3,4页
select * from (
   select a.*,rownum rn from (
      select * from emp where ename>='K' order by ename) a
   where rownum<=6) where rn>3
版权说明

  如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
  作      者:温景良
  文章出处:http://wenjl520.cnblogs.com/  或  http://www.cnblogs.com/

posted @ 2009-04-28 23:43 温景良(Jason) Views(180) Comments(0) Edit 收藏
 

公告

 
本文转自我的程序人生博客园博客,原文链接:http://www.cnblogs.com/wenjl520/archive/2009/04/28/1445766.html,如需转载请自行联系原作者
 
上一篇:如何让门店员工积极地投入到零售门店RFID项目?


下一篇:Oracle数据库中的分页--rownum