因为效率问题,不能使用order by对结果进行排序,有没有其他方法可以使查询结果按照pk升序排列

解决方案 »

  1.   

    你select之前已经在table按pk排序咯。
      

  2.   

    建个mview, mview里是排序好的... (甚至可以建多个partition的mview)
      

  3.   

    大家一起来研究oracle是默认用主键还是用rowid排序
      

  4.   

    SQL> create table wiler_cs (
      2   nnid number(5) not null,
      3   nname varchar2(20)
      4  );Table createdSQL> alter table wiler_cs add primary key (nnid);Table alteredSQL> insert into wiler_cs
      2  values(1,'1');1 row insertedSQL> insert into wiler_cs
      2  values(10,'10');1 row insertedSQL> insert into wiler_cs
      2  values(9,'9');1 row insertedSQL> insert into wiler_cs
      2  values(8,'8');1 row insertedSQL> insert into wiler_cs
      2  values(3,'3');1 row insertedSQL> insert into wiler_cs
      2  values(5,'5');1 row insertedSQL> commit;Commit completeSQL> select * from wiler_cs;  NNID NNAME
    ------ --------------------
         1 1
        10 10
         9 9
         8 8
         3 3
         5 56 rows selectedSQL> 以上是测试结果,由测试结果看出,oracle的默认排序是用rowid排序的
      

  5.   

    本质来说不是根据rowid排序,
    读的时候是通过数据块顺序的读出的
      

  6.   

    学习
    不是根据rowid排序,而是根据读出的先后顺序排序
    谢谢大版
      

  7.   

    更好的方法好象没有吧  也许是我们孤陋寡闻  反正不是很清楚 
    ORDER BY 主键应该不会很慢吧
      

  8.   

    有两种情况下,是默认排序的:
    第一:Distinct
    第二:Group by 如果是以上的两种语句,可以不用排序。