64.View the Exhibit and examine the data in the PROMO_CATEGORY and PROMO_COST columns of

来源:互联网 发布:c语言简单程序实例 编辑:程序博客网 时间:2024/05/15 17:08
64.View the Exhibit and examine the data in the PROMO_CATEGORY and PROMO_COST columns of
the PROMOTIONS table.
Evaluate the following 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 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
解析:在设置列别名的时候,是不区分大小写的,数据库都会转换成大写,但是如果加上双引号后
就会保持原样,第一个sql语句,order by code,其实会转化为 order by CODE,而列别名"code"
还是保持小写,因此会报错
SQL> select '1' "code" from dual order by code;
select '1' "code" from dual order by code
                                     *
ERROR at line 1:
ORA-00904: "CODE": invalid identifier
第二条sql语句,使用的是阿拉伯数字,它代表的其实是列的位置,从1开始
0 0
原创粉丝点击