您需要使用 LEAD()。
根据“a_horse_with_no_name”评论更正:LEAD(sal, 1, sal)
UPDATE emp_test a
SET sal =
(
SELECT LEAD(sal, 1, sal) OVER (ORDER BY sal) AS sal_next
FROM scott.emp b
WHERE a.empno = b.empno
)
/
与 ename 相同:
SELECT empno, ename, job, sal,
LEAD(ename, 1, ename) OVER (ORDER BY ename) AS name_next
FROM scott.emp
/
EMPNO ENAME JOB SAL NAME_NEXT
--------------------------------------------
7876 ADAMS CLERK 1100 ALLEN
7499 ALLEN SALESMAN 1600 BLAKE
7698 BLAKE MANAGER 2850 CLARK
7782 CLARK MANAGER 2450 FORD
....
7844 TURNER SALESMAN 1500 WARD
7521 WARD SALESMAN 1250 WARD
这将不起作用:
SELECT * FROM scott.emp
WHERE ROWNUM = 5
/
但这将:
SELECT * FROM scott.emp
WHERE ROWNUM <= 5
/