25 lines
631 B
Plaintext
25 lines
631 B
Plaintext
![]() |
Oracle's ``++ROWNUM++`` is a pseudo column that numbers the rows in a result set. Unfortunately, it numbers the rows in the set _before_ ordering is applied. So combining the two in the same query won't get you the results you expect. Instead, you should move your selection and ordering into a subquery, and use ``++ROWNUM++`` only on the outer query.
|
||
|
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
SELECT fname, lname, deptId
|
||
|
FROM employee
|
||
|
WHERE rownum <= 10
|
||
|
ORDER BY salary -- Noncompliant
|
||
|
----
|
||
|
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
SELECT *
|
||
|
FROM ( SELECT fname, lname, deptId
|
||
|
FROM employee
|
||
|
ORDER BY salary
|
||
|
)
|
||
|
WHERE rownum <= 10
|
||
|
----
|
||
|
|