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


    94. Examine the structure of the PROGRAMS table:

    name            Null        Type

    PROG_ID         NOT NULL    NUMBER(3)

    PROG_COST                  NUMBER(8,2)

    START_DATE      NOT NULL    DATE

    END_DATE                   DATE

    Which two SQL statements would execute successfully? (Choose two.)

    A. SELECT NVL(ADD_MONTHS(END_DATE,1),SYSDATE)

    FROM programs;

    B. SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE))

    FROM programs;

    C. SELECT NVL(MONTHS_BETWEEN(start_date,end_date),'Ongoing')

    FROM programs;

    D. SELECT NVL(TO_CHAR(MONTHS_BETWEEN(start_date,end_date)),'Ongoing')

    FROM programs;

    Answer: AD

    本题主要考NVL的参数的数据类型是否相同的问题。

    NVL函数见http://blog.csdn.net/rlhua/article/details/11805803

    1、根据题意创建PROGRAMS表

    sh@TEST0910> create table PROGRAMS
      2  (prog_id number(3) not null,
      3  prog_cost number(8,2),
      4  start_date date not null,
      5  end_date date);
     
    Table created.
    2、插入一行数据测试用。
     
    sh@TEST0910> select * from  PROGRAMS;
     
       PROG_ID  PROG_COST START_DAT END_DATE
    ---------- ---------- --------- ---------
             1       10.1 18-SEP-13 19-SEP-13
     
     
    3、开始测试:
    A答案:
    sh@TEST0910> SELECT NVL(ADD_MONTHS(END_DATE,1),SYSDATE) FROM programs;
     
     
    NVL(ADD_M
    ---------
    19-OCT-13
     
    ADD_MONTHS returns the date date plus integer months.
    ADD_MONTHS 返回的是数据类型是Date和sysdate类型一致,故正确。
     
    B答案:
    sh@TEST0910> SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE))
      2  FROM programs;
    SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE))
                   *
    ERROR at line 1:
    ORA-01858: a non-numeric character was found where a numeric was expected
     
    sh@TEST0910> select SYSDATE-END_DATE from  programs;
     
    SYSDATE-END_DATE
    ----------------
           .9937963
     
    SYSDATE-END_DATE 返回的是一个数值类型,与sysdate类型不一致。故错误。
     
    C答案:
     
    sh@TEST0910> SELECT NVL(MONTHS_BETWEEN(start_date,end_date),'Ongoing')
      2   FROM programs;
    SELECT NVL(MONTHS_BETWEEN(start_date,end_date),'Ongoing')
                                                   *
    ERROR at line 1:
    ORA-01722: invalid number
     
    sh@TEST0910> select MONTHS_BETWEEN(start_date,end_date) from  programs;
     
    MONTHS_BETWEEN(START_DATE,END_DATE)
    -----------------------------------
                             -.03225806
     
    MONTHS_BETWEEN(start_date,end_date)返回是数值类型,与'Ongoing'类型不一致,故错误
     
    使用to_char使他们类型一致,就是正确的了
    sh@TEST0910> SELECT NVL(to_char(MONTHS_BETWEEN(start_date,end_date)),'Ongoing')
      2  FROM programs;
     
    NVL(TO_CHAR(MONTHS_BETWEEN(START_DATE,EN
    ----------------------------------------
    -.03225806451612903225806451612903225806
     
    D答案:NVL内的参数一致,故正确。
    sh@TEST0910> SELECT NVL(TO_CHAR(MONTHS_BETWEEN(start_date,end_date)),'Ongoing')
      2   FROM programs;
     
    NVL(TO_CHAR(MONTHS_BETWEEN(START_DATE,EN
    ----------------------------------------
    -.03225806451612903225806451612903225806
  • 相关阅读:
    hikariCP性能调优
    Mysql 8.0 my.ini 系统变量设置Server System Variable Reference
    MySQL性能测试 : 新的InnoDB Double Write Buffermysql .dblwr
    MySQL MyISAM/InnoDB高并发优化经验
    解决NAVICAT 无法连接MYSQL8.0.12_可视化工具无法连接 MYSQL 8.0
    quartz 节点争抢Job 问题算法
    认识Flink中的Window
    多个用户同时update同一张表中的同一条记录会导致死锁吗?MySQL数据库?
    java.util.Base64 基本使用
    解决JDK1.8 编译时提示 程序包com.sun.image.codec.jpeg不存在的问题
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13317239.html
Copyright © 2020-2023  润新知