View definitions in Oracle: “Oracle allows the ORDER BY clause inside a CREATE VIEW definition.” Evaluate whether this statement is valid for standard view creation.

Difficulty: Easy

Correct Answer: Incorrect

Explanation:


Introduction / Context:
Standard relational theory treats base tables and views as unordered sets of rows. Sorting is a presentation concern for queries that consume the view. This question asks whether Oracle permits ORDER BY directly in a normal (non-materialized) view's defining SELECT.



Given Data / Assumptions:

  • We are discussing conventional (non-materialized) views created by CREATE VIEW v AS SELECT ...
  • Oracle enforces that a view does not inherently impose row order.
  • Consumers of the view may specify ORDER BY when selecting from the view.


Concept / Approach:
In Oracle, CREATE VIEW ... AS SELECT ... cannot include ORDER BY unless the ORDER BY is used in a top-N style query where ORDER BY appears in a subquery paired with row-limiting logic (for example, ROWNUM or 12c row-limiting clause). Even then, the outermost defining query of a simple view normally must not end with ORDER BY. Therefore, stating that Oracle allows ORDER BY in the view definition as a general rule is incorrect. Materialized views, however, can have refresh and indexing strategies that affect access paths; still, row order is not guaranteed without ORDER BY in the consuming query.



Step-by-Step Solution:

Attempt CREATE VIEW v AS SELECT * FROM emp ORDER BY ename; → results in error.Place ORDER BY in a subquery for row limiting (advanced cases) → still, the outer view is unordered.Select from the view with ORDER BY to guarantee the desired order.Conclusion: Oracle does not generally allow ORDER BY directly in the view definition.


Verification / Alternative check:
Test in Oracle: try creating a simple view with ORDER BY and observe the compilation error; then query the view with an ORDER BY and confirm it works as intended.



Why Other Options Are Wrong:

  • “Correct” overstates Oracle capability for standard views.
  • Materialized views and READ ONLY flags do not change the unordered nature of views.
  • Row-limiting with FETCH FIRST belongs in queries that consume the view; it does not create a guaranteed order for the view result.


Common Pitfalls:
Expecting a view to “remember” sort order; depending on implicit order due to indexes.



Final Answer:
Incorrect

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion