rspec/rules/S4062/plsql/rule.adoc

32 lines
788 B
Plaintext
Raw Normal View History

2021-05-19 01:18:45 +00:00
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
----
ifdef::env-github,rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]