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

    104. Examine the structure of the PROMOS table:

    name              Null        Type

    PROMO_ID          NOT NULL    NUMBER(3)

    PROMO_NAME                   VARCHAR2(30)

    PROMO_START_DATE NOT NULL    DATE

    PROMO_END_DATE               DATE

    You want to generate a report showing promo names and their duration (number of days). If the

    PROMO_END_DATE has not been entered, the message 'ONGOING' should be displayed.

    Which queries give the correct output? (Choose all that apply.)

    A. SELECT promo_name, TO_CHAR(NVL(promo_end_date -promo_start_date,'ONGOING'))  

    FROM promos;

    B. SELECT promo_name,COALESCE(TO_CHAR(promo_end_date - promo_start_date),'ONGOING')  

    FROM promos;

    C. SELECT promo_name, NVL(TO_CHAR(promo_end_date -promo_start_date),'ONGOING') 

    FROM promos;

    D. SELECT promo_name, DECODE(promo_end_date -promo_start_date,NULL,'ONGOING',promo_end_date - promo_start_date)

    FROM promos;

    E. SELECT promo_name, decode(coalesce(promo_end_date,promo_start_date),null,'ONGOING',

    promo_end_date - promo_start_date)

    FROM promos;

    Answer: BCD
     答案解析:
    ANVL要求括号内参数的类型需一致,,NVL(promo_end_date -promo_start_date,'ONGOING')此处类型不一致,一个为数值型,一个为字符型
    B, COALESCE 需括号内参数类型需一致,TO_CHAR(promo_end_date - promo_start_date),'ONGOING') ,此处使用to_char转换,两个参数都为字符型,可以比较。正确。
    C, NVL(TO_CHAR(promo_end_date -promo_start_date),'ONGOING'),NVL括号内两个参数都为字符型,正确。
    D,表达式正确
    E,不满足题意,coalesce返回第一个不为空的值,因为promo_start_date肯定不为空,所以即使promo_end_date为空,coalesce也会返回promo_start_dat,所以都会显示promo_end_date - promo_start_date值,即当promo_end_date为空时,还是会显示空(注意,如果你直接指定NULL-sysdate会报转换数据类型错,而在字段里就可以减,并返回空。

  • 相关阅读:
    后CIO人如何规划职业生涯
    数据库设计三大范式应用实例剖析
    一个女孩从软件测试工程师到主管的成长
    一本适合测试初学者阅读的中文译著
    再看微软团队文化
    阳光的测试工作历程(转载)
    hdu 2795
    hdu 2426
    hdu 2255+hdu 3395
    hdu 3729
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13316873.html
Copyright © 2011-2022 走看看