oracle分页用rownum分页!求高手帮忙噶! SQL> select a1.*,rownum rn from (select * from emp) a1 where rownum>2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO RN ----- ---------- --------- ----- ----------- --------- --------- ------ ----------
Executed in 0.031 seconds
SQL> select a1.*,rownum rn from (select * from emp) a1 where rownum<2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO RN ----- ---------- --------- ----- ----------- --------- --------- ------ ---------- 7369 SMITH CLERK 7902 1980/12/17 800.00 20 1
Executed in 0.032 seconds
求解释在oracle的PL/SQL Developer中使用这个“select a1.*,rownum rn from (select * from emp) a1 where rownum>2;” 为什么不能查询出数据?emp表中一共有14条数据,然而把rownum>2改成rownum<2时就能查询出数据
既然你已经用子查询后建立一个字段rn,直接在外层用rn就行 select a1.*,rownum rn from (select * from emp) where rn>2;
------解决方案-------------------- 首先熟悉伪列 rownum .基于已有的结果集。那么如果直接有rownum 只能是小于。 假如取11行到20行, select a1.* from (select t.*,rownum row_num from emp where rownum<20) a1 where row_num>=11 and row_num <20;
------解决方案--------------------
------解决方案--------------------
SQL code
--row_number用这个排序函数分页
select *
from (select *,row_number()over(order by EMPNO) as rn from emp) as t
where t.rn between 2 and 3
------解决方案-------------------- 楼主写法错误了,变化的rownum是不能用>来做条件,正确写法
SQL code
select * from (select *,rownum rn from emp) a1 where rn >2