OCP-1Z0-051-V9 02-93题

分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

               

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, thenNVL 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 returnsVARCHAR2 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

 

           

分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值