105.Examine the structure of the PROMOS table:

来源:互联网 发布:avdb.la新域名2017 编辑:程序博客网 时间:2024/06/05 19:40
105.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     NOT NULL    DATE


You want to display the list of promo names with the message 'Same Day' for promos that started and
ended on the same day.


Which query gives the correct output?
A.SELECT promo_name, NVL(NULLIF(promo_start_date, promo_end_date), 'Same Day') FROM promos;
B.SELECT promo_name, NVL(TRUNC(promo_end_date - promo_start_date), 'Same Day') FROM promos;
C.SELECT promo_name, NVL2(TO_CHAR(TRUNC(promo_end_date-promo_start_date)), NULL,'Same Day') FROM promos;
D.SELECT promo_name, DECODE((NULLIF(promo_start_date, promo_end_date)), NULL,'Same day') FROM promos;
答案:D
解析:
A:错误,nvl 参数类型必须相同
B:错误,同上
C:错误,TO_CHAR(TRUNC(promo_end_date-promo_start_date)这个值肯定不为null,nvl2的结果就是null
D:正确
0 0