QuestionQ46

VerifiedRestricting and Sorting Data

Refer to the exhibit and review the PROMO_CATEGORY and PROMO_COST column data in the PROMOTIONS table.

Question Image

Consider these two queries:

SQL>SELECT DISTINCT promo_category to_char(promo_cost)"code"  
FROM promotions -  
ORDER BY code;  
  
SQL>SELECT DISTINCT promo_category promo_cost "code"  
FROM promotions -  
ORDER BY 1;  

Which statement is true about executing the preceding queries?

Explanation

When a column alias is created using double quotes, Oracle preserves its exact case and treats subsequent references to it as case-sensitive, whereas an unquoted identifier elsewhere in the statement is automatically folded to uppercase before being resolved. Referencing a lowercase, double-quoted alias with an unquoted identifier in an ORDER BY clause therefore fails to find a matching column and raises an invalid-identifier error, while ordering by the select-list position number bypasses alias-name resolution entirely, which is why only the query using ORDER BY 1 executes successfully.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!