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

来源:互联网 发布:时光倒流软件 编辑:程序博客网 时间:2024/05/21 03:27

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

 

原创粉丝点击