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

    93. View the Exhibit and examine the structure of the CUSTOMERS table.

    Using the CUSTOMERS table, y ou need to generate a report that shows  an increase in the credit limit

    by 15% for all customers. Customers whose credit limit has not been entered should have the message "

    Not Available"  displayed.

    Which SQL statement would produce   the required result? 

    A. SELECT NVL(cust_credit_limit,'Not Available')*.15 "NEW CREDIT"

    FROM customers;

    B. SELECT NVL(cust_credit_limit*.15,'Not Available') "NEW CREDIT" 

    FROM customers;

    C. SELECT TO_CHAR(NVL(cust_credit_limit*.15,'Not Available')) "NEW CREDIT" 

    FROM customers;

    D. SELECT NVL(TO_CHAR(cust_credit_limit*.15),'Not Available') "NEW CREDIT"

    FROM customers;

    Answer: D
    1、NVL

    官方解释:

    Purpose

    NVL lets you replace null (returned as a blank) with a string in the results of a query.

    If expr1 is null, then NVL returns expr2. Ifexpr1 is not null, then NVL returns expr1.

    如果expr1是null,则返回expr2,如果expr1 is not null,则返回expr1.

    The arguments expr1 and expr2 can have any data type. If their data types are different, then Oracle Database implicitly converts one to the other.

    If they cannot be converted implicitly, then the database returns an error.

    expr1 and expr2 可以是任意的数据类型,但他们必须是同一数据类型,或者是隐式转换为同一数据类型,又或者是显示转换为同一数据类型。

    如果他们不是同一类型,则报错。

    The implicit conversion is implemented as follows:

    • If expr1 is character data, then Oracle Database converts expr2 to the data type ofexpr1 before comparing them and returns VARCHAR2 in the character set ofexpr1.

    • 如果expr1 是字符类型,则expr2在比较前转换为expr1的数据类型,在进行比较。

    • If expr1 is numeric, then Oracle Database determines which argument has the highest numeric precedence, implicitly converts the other argument to that data type, and returns that data type.

    • 如果expr1是数字类型,则判断哪个参数的数据类型高就隐式转为哪个数据类型。

    官方参考:http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions119.htm#sthref1312

    2、Data Conversion

    官方参考:http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements002.htm#sthref306

    此处考试的意图在与NVL函数里参数的数据类型的一致性以及数据类型之间的转换。

    由题意可知,先用同to_char函数显示将cust_credit_limit*.15转换为字符类型,才能达成数据类型一致。

    A答案:

    sh@TEST0910> SELECT NVL(cust_credit_limit,'Not Available')*.15 "NEW CREDIT" FROM customers;
    SELECT NVL(cust_credit_limit,'Not Available')*.15 "NEW CREDIT" FROM customers
                                 *
    ERROR at line 1:
    ORA-01722: invalid number

    B答案:

    sh@TEST0910> SELECT NVL(cust_credit_limit*.15,'Not Available') "NEW CREDIT" FROM customers;
    SELECT NVL(cust_credit_limit*.15,'Not Available') "NEW CREDIT" FROM customers
                                     *
    ERROR at line 1:
    ORA-01722: invalid number

    C答案:

    sh@TEST0910> SELECT TO_CHAR(NVL(cust_credit_limit*.15,'Not Available')) "NEW CREDIT" FROM customers;
    SELECT TO_CHAR(NVL(cust_credit_limit*.15,'Not Available')) "NEW CREDIT" FROM customers
                                             *
    ERROR at line 1:
    ORA-01722: invalid number

    D答案:

    sh@TEST0910> SELECT NVL(TO_CHAR(cust_credit_limit*.15),'Not Available') "NEW CREDIT"
      2  FROM customers where rownum<5;
     
    NEW CREDIT
    ----------------------------------------
    225
    1050
    1650
    225
  • 相关阅读:
    数据结构与算法 -- 动态规划算法
    数据结构与算法 -- 回溯算法
    数据结构与算法 -- 图
    数据结构与算法无用随笔
    算法集锦
    基于Zookeeper实现多进程分布式锁
    自己动手写线程池
    maven配置国内阿里云镜像
    自己动手写java锁
    使用jconsole监控JVM内存
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13317240.html
Copyright © 2011-2022 走看看