• OCP-1Z0-051-V9.02-105题


    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,'SameDay') FROM promos;

    D. SELECT promo_name, DECODE((NULLIF(promo_start_date, promo_end_date)), NULL,'Same day') FROM promos;

    Answer: D

    答案解析:

    A。NULLIF里面额数据类型为date与 'Same Day'字符串类型不匹配,错误。

    B。TRUNC将小数部分截断,但类型不一致,错误。

    C。TO_CHAR(TRUNC(promo_end_date-promo_end_date)),如果相等,TRUNC为0,to_char后,字符为0,即始终有值,NVL2返回第二个值,即NULL

    sh@TEST0924>  SELECT promo_name, NVL2(TO_CHAR(TRUNC(promo_end_date-promo_end_date)), NULL,'SameDay') FROM PROMOTIONS;


    PROMO_NAME                     NVL2(TO

    ------------------------------ -------

    NO PROMOTION #

    newspaper promotion #16-108

    post promotion #20-232

    newspaper promotion #16-349

    internet promotion #14-471

    D。实验验证:正确的。
    scott@TESTDB> SELECT  DECODE((NULLIF('11-mon-01','11-mon-01')),null,'same') from dual;
     
    DECO
    ----
    same


    scott@TESTDB> SELECT  DECODE(null,null,'same') from dual;
     
    DECO
    ----
    same
     

  • 相关阅读:
    Maven学习
    Android屏幕适配
    Java多线程中的死锁问题[转]
    数据结构基本概念和算法分析
    AsyncTask(异步任务)
    Android自定义滑动开关按钮
    记录一些我记不住的技术
    2017携程Web前端实习生招聘笔试题总结
    JavaScript ES5面向对象实现一个todolist
    原生JavaScript实现一个简单的todo-list
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13316872.html
Copyright © 2020-2023  润新知