order by 排序

fuyou@ORCL> select * from emp order by 1;

     EMPNO ENAME                JOB              MGR HIREDATE              SAL       COMM     DEPTNO
---------- -------------------- --------- ---------- -------------- ---------- ---------- ----------
      7369 SMITH                CLERK           7902 17-12月-80            800                    20
      7499 ALLEN                SALESMAN        7698 20-2月 -81           1600        300         30
      7521 WARD                 SALESMAN        7698 22-2月 -81           1250        500         30
      7566 JONES                MANAGER         7839 02-4月 -81           2975                    20
      7654 MARTIN               SALESMAN        7698 28-9月 -81           1250       1400         30
      7698 BLAKE                MANAGER         7839 01-5月 -81           2850                    30
      7782 CLARK                MANAGER         7839 09-6月 -81           3675                    10
      7788 SCOTT                ANALYST         7566 09-12月-82           3000                    20
      7839 KING                 PRESIDENT            17-11月-81           7500                    10
      7844 TURNER               SALESMAN        7698 08-9月 -81           1500          0         30
      7876 ADAMS                CLERK           7788 12-1月 -83           1100                    20
      7900 JAMES                CLERK           7698 03-12月-81            950                    30
      7902 FORD                 ANALYST         7566 03-12月-81           3000                    20
      7934 MILLER               CLERK           7782 23-1月 -82           1300                    40

当order by 后面跟字面量(数字第几更或列名时),就根据基例来排序
但如果order by 后面一个函数,刚对每一行都使用函数来计数,最后按每一行函数的计数结果来排序
如:
fuyou@ORCL> select * from emp order by dbms_random.random();

     EMPNO ENAME                JOB              MGR HIREDATE              SAL       COMM     DEPTNO
---------- -------------------- --------- ---------- -------------- ---------- ---------- ----------
      7499 ALLEN                SALESMAN        7698 20-2月 -81           1600        300         30
      7566 JONES                MANAGER         7839 02-4月 -81           2975                    20
      7900 JAMES                CLERK           7698 03-12月-81            950                    30
      7782 CLARK                MANAGER         7839 09-6月 -81           3675                    10
      7934 MILLER               CLERK           7782 23-1月 -82           1300                    40
      7902 FORD                 ANALYST         7566 03-12月-81           3000                    20
      7844 TURNER               SALESMAN        7698 08-9月 -81           1500          0         30
      7521 WARD                 SALESMAN        7698 22-2月 -81           1250        500         30
      7788 SCOTT                ANALYST         7566 09-12月-82           3000                    20
      7369 SMITH                CLERK           7902 17-12月-80            800                    20
      7698 BLAKE                MANAGER         7839 01-5月 -81           2850                    30
      7839 KING                 PRESIDENT            17-11月-81           7500                    10
      7654 MARTIN               SALESMAN        7698 28-9月 -81           1250       1400         30
      7876 ADAMS                CLERK           7788 12-1月 -83           1100                    20

你可能感兴趣的:(order by)