首页 > 数据库 > Oracle > OCP 1Z0-051-64
Evaluate the following two queries:
|
SELECT DISTINCT promo_category, to_char(promo_cost) "code" FROM promotions ORDER BY code; SELECT DISTINCT promo_category, promo_cost "code" FROM promotions ORDER BY 1; |
Which statement is true regarding the execution of the above queries?
A. Only the first query executes successfully.
B. Only the second query executes successfully.
C. Both queries execute successfully but give different results.
D. Both queries execute successfully and give the same result.
答案:(B)
解析:
|
--A(X), 列的别名加了引号,order by中别名也必须加引号 scott@TESTDB11>select sal, ename as "name" from emp order by name; select sal, ename as "name" from emp order by name * ERROR at line 1: ORA-00904: "NAME": invalid identifier scott@TESTDB11>select sal, ename as "name" from emp order by "name"; SAL name ---------- ---------- 1100 ADAMS 1600 ALLEN 2850 BLAKE 2450 CLARK 3000 FORD 950 JAMES 2975 JONES 5000 KING 1250 MARTIN 1300 MILLER 3000 SCOTT 800 SMITH 1500 TURNER 1250 WARD 14 rows selected. |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/17013648/viewspace-1161528/ ,如需转载,请注明出处,否则将追究法律责任。