oracle里的rownum的使用。
select * from (select rownum num,student_name from student) where num >10;
这样取也来的东西并不是前10条。
取前10条应该怎么写啊,求教高手。

解决方案 »

  1.   

    select student_name from student
    where rownum<=10  //前10条
    你写的是从10条到结束
      

  2.   

    前10
    select * from tbl where rownum < =1011-20
    select * from (select a.*, rownum rn from tbl where rownum <=20) where rn >=11
      

  3.   

    select student_name from student where rownum<=10
      

  4.   

    为什么rownum必须从1开始取?是因为他是一个伪列,不是真正存在的。
    例子
    -- 成功输出之后才会加1    
    Select * from t where rownum = 2Rownum = 1
    For x in ( select * from t )
    Loop
       if ( rownum = 2 )
       then 
          output record
          rownum = rownum+1;
       end if
    End loop
    这样永远执行不到
      

  5.   

    ROWNUMROWNUM returns a number indicating the order in which a row was selected from a table. The first row selected has a ROWNUM of 1, the second row has a ROWNUM of 2, and so on. If a SELECT statement includes an ORDER BY clause, ROWNUMs are assigned to the retrieved rows before the sort is done.You can use ROWNUM in an UPDATE statement to assign unique values to each row in a table. Also, you can use ROWNUM in the WHERE clause of a SELECT statement to limit the number of rows retrieved, as follows:DECLARE
       CURSOR c1 IS SELECT empno, sal FROM emp
          WHERE sal > 2000 AND ROWNUM < 10;  -- returns 10 rowsThe value of ROWNUM increases only when a row is retrieved, so the only meaningful uses of ROWNUM in a WHERE clause are... WHERE ROWNUM < constant;
    ... WHERE ROWNUM <= constant;