Добрый день.
Есть табле Employee :
hr@DEV>SELECT DBMS_METADATA.GET_DDL('TABLE','EMPLOYEE',USER) from dual;
CREATE TABLE "HR"."EMPLOYEE"
( "EMPNO" NUMBER(3,0),
"ENAME" VARCHAR2(20),
"HIREDATE" DATE,
"ORIG_SALARY" NUMBER(6,0),
"CURR_SALARY" NUMBER(6,0),
"REGION" VARCHAR2(2),
CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") ......................
.......
/
hr@DEV> select * from employee
EMPNO ENAME HIREDATE ORIG_SALARY CURR_SALARY RE
---------- -------------------- --------- ----------- ----------- --
100 Steven 17-JUN-87 24000 24010 W
101 Neena 21-SEP-89 400 17020 E
102 Lex 13-JAN-93 50000 48790 W
103 Alexander 03-JAN-90 9000 9040 E
104 Bruce 21-MAY-91 6000 6050 E
105 David 25-JUN-97 4800 4860 E
106 Valli 05-FEB-98 65400 4870 W
7 rows selected.
Вариант 1: ( Нормално отсортировал по
ename )
hr@DEV>select empno , ename , orig_salary , row_number()
over ( order by orig_salary desc) Banzay from employee order by ename;
EMPNO ENAME ORIG_SALARY BANZAY
---------- -------------------- ----------- ----------
103 Alexander 9000 4
104 Bruce 6000 5
105 David 4800 6
102 Lex 50000 2
101 Neena 400 7
100 Steven 24000 3
106 Valli 65400 1
7 rows selected.
А ПОЧЕМУ :
hr@DEV>select empno , ename , orig_salary , row_number()
over ( order by orig_salary desc) Banzay from employee order by empno;
EMPNO ENAME ORIG_SALARY BANZAY
---------- -------------------- ----------- ----------
106 Valli 65400 1
102 Lex 50000 2
100 Steven 24000 3
103 Alexander 9000 4
104 Bruce 6000 5
105 David 4800 6
101 Neena 400 7
7 rows selected.
НЕ СОРТИРУЕТ ПО
empno???
hr@DEV>select banner from v$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE 9.2.0.1.0 Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
Спасибо.
© Бомж Inc.