rspec/rules/S4062/plsql/rule.adoc

46 lines
967 B
Plaintext
Raw Normal View History

== Why is this an issue?
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
2021-05-19 01:18:45 +00:00
2022-02-04 17:28:24 +01:00
[source,sql]
2021-05-19 01:18:45 +00:00
----
SELECT fname, lname, deptId
FROM employee
WHERE rownum <= 10
ORDER BY salary -- Noncompliant
----
=== Compliant solution
2021-05-19 01:18:45 +00:00
2022-02-04 17:28:24 +01:00
[source,sql]
2021-05-19 01:18:45 +00:00
----
SELECT *
FROM ( SELECT fname, lname, deptId
FROM employee
ORDER BY salary
)
WHERE rownum <= 10
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]