Question 1
Consider the following statement executed against the `employees` table. What is the result? ```sql SELECT first_name, salary FROM employees ORDER BY 3; ```
A. ORA-01785Correct answer
A bare integer in ORDER BY is a 1-based reference to a SELECT-list column by its position. The SELECT list has only two expressions (first_name, salary), so position 3 is out of range and Oracle raises ORA-01785: 'ORDER BY item must be the number of a SELECT-list expression'.
B. ORA-00904
ORA-00904 (invalid identifier) is raised for an unknown column NAME. A bare integer in ORDER BY is parsed as a SELECT-list position, not as an identifier lookup, so the invalid-identifier error does not apply.
C. ORA-00936
ORA-00936 (missing expression) flags a syntactically incomplete clause. ORDER BY 3 is complete and parses fine; the failure is a semantic out-of-range position, not a missing expression.
D. The statement runs successfully; ORDER BY 3 sorts by the constant value 3, leaving the rows in their inserted order.
An unqualified integer in ORDER BY is ALWAYS a SELECT-list position reference, never a constant expression. It cannot silently sort by the literal 3, so an out-of-range position is rejected rather than ignored.
Explanation
In an ORDER BY clause an unqualified integer is interpreted as the ordinal position of a column in the SELECT list, not as a literal value. When that position exceeds the number of selected expressions, Oracle cannot map it to a column and rejects the statement. Because the select list here contains only two items, position 3 is invalid.