select * from (select rownum r,tbname.* from tbname ) where r = 5;

解决方案 »

  1.   

    最好是
    select * from (select rownum rn,tbname.* from tbname
    where rownum<=5) t
    where rn>4;
      

  2.   

    =5是不可以的吧,=1是可以的,1以上的就是空的啦,只能用<或=,不能直接等的!
    也可以用数据集相减的方法了,这个问题说的很多啦,呵呵!
    select * from tabname where rownum<=5 
    minus
    select * from tabname where rownum<=4
      

  3.   

    select * from (select rownum num,c_well.* from c_well) where num=5
      

  4.   

    select * from (select rownum num ,t1.* from t1) where num = 5;
      

  5.   

    select * from TableName where rownum=行号;
      

  6.   

    select * from TableName where rownum=行号 肯定不行
    lialin的不错
      

  7.   

    risingsoft(一苇渡江) 的select * from TableName where rownum=行号; 这个方法肯定不行的。
    其他的我看都行。
    不过楼主问这个问题啊好象意义不大,现实应用中哪有找表中第几行的,谁知道第5行是个什么东西,这跟找第6行,第7行、任意行有什么区别呢?那么特别指定的第5行就没什么意义了,我想楼主你的意思可能是找按照某一列排序后的第五行吧?如果这样的话,要用到函数rank() over()或者dense_rank() over()了
      

  8.   

    等于行号的可以么?没这么用过。
    支持bzszp的方法。
      

  9.   

    select * from tbname where rownum <= 4
    minus
    select * from tbname where rownum <= 5
      

  10.   

    sorry  上面的应该是:
    select * from tbname where rownum <= 5
    minus
    select * from tbname where rownum <= 4
      

  11.   

    除了orcale,可以用rowid之外,其他的数据库俺是这样做的:(sqlserver)
    1在sql里,获得任意一行的思路:
        1,获得每一行的行号:只能灵活应用count()函数。在子查询中,主键(或非重复行--唯一)大于(小于)父表的对应行。
         例:
            Select name, (select count(1) from sysobjects b where xtype='U' and b.name > t.name)  cou  from sysobjects t where   xtype='U' 
    /*  sysobjects表----记录了数据库中所有对象的信息。当 xtype ='u',返回所有用户表的纪录,name 列--用户表的表名*/
    name           cou
    -------------------------------------
    titleauthor      1
    stores           2
    sales            3
    roysched         4
    .........          ...
      2,有了行号,就可查询任意行了,呵呵,,,,
        Select name from sysobjects t where xtype='U' and (select count(1) from sysobjects b where xtype='U' and b.name >     t.name)=4
       name
    ----------------------------------
       roysched
      

  12.   

    在oracle里也可一这样用
    select * from nh_bank t  where (select count(1) from nh_bank n2 where n2.bank_name > t.bank_name) = 5 注意 大于号比较的条件。