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;
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 convertsexpr2
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答案:
B答案:
C答案:
D答案: