zoukankan      html  css  js  c++  java
  • OCP-1Z0-051-V9.02-64题

    64. View the E xhibit 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.
    Answer: B
    答案解析:
    order by 可以指定表达式、别名或列位置作为排序条件,别名要完全匹配
    列别名并没有完全匹配,所以报错。

    sh@TEST0924>  SELECT DISTINCT promo_category, to_char(promo_cost)"code"

      2  FROM promotions

      3  ORDER BY code;

    ORDER BY code

             *

    ERROR at line 3:

    ORA-00904: "CODE": invalid identifier

     应该改为:

    sh@TESTDB> SELECT DISTINCT promo_category, to_char(promo_cost)"code"
      2  FROM promotions
      3  where rownum<6
      4   ORDER BY "code";
     
    PROMO_CATEGORY                 code
    ------------------------------ ----------------------------------------
    NO PROMOTION                   0
    newspaper                      200
    post                           300
    newspaper                      400
    internet                       600

     第二个SQL如下,可执行成功,原题差一个逗号

    sh@TESTDB> SELECT DISTINCT promo_category,promo_cost "code"
      2  FROM promotions
      3  where rownum<6
      4   ORDER BY 1;
     
    PROMO_CATEGORY                       code
    ------------------------------ ----------
    NO PROMOTION                            0
    internet                              600
    newspaper                             200
    newspaper                             400
    post                                  300
  • 相关阅读:
    re | [SWPU2019]ReverseMe
    wp | re | 2020“巅峰极客”网络安全技能挑战赛
    re | [CFI-CTF 2018]IntroToPE
    re | [FlareOn1]Bob Doge
    re | [ACTF新生赛2020]SoulLike
    re | [GKCTF2020]Chelly's identity
    ospf配置与ofps选举DR/BDR
    静态路由的配置
    配置三层交换机实现vlan间通信
    hybrid接口
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13316907.html
Copyright © 2011-2022 走看看