zoukankan      html  css  js  c++  java
  • 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
     

  • 相关阅读:
    string截断
    winform截屏
    android自定义tabhost,tabcontent用intent获得
    Eclipse引入jar包的三种方式
    jquery dataTable的学习
    jquery datatable 参数
    Sql Server中三种字符串合并方法的性能比较
    sql表设计
    开发守则
    App Store2016年最新审核规则
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13316872.html
Copyright © 2011-2022 走看看