93.View the Exhibit and examine the structure of the CUSTOMERS table. Using the CUSTOMERS table, y o

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?

93.View the Exhibit and examine the structure of the CUSTOMERS table. Using the CUSTOMERS table, y o_第1张图片

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;
答案:D
这道题其实主要考察nvl函数参数类型的问题,nvl(exp1,exp2),如果exp1为null那么返回exp2,
exp1和exp2类型必须相同,如果不相同那么系统会将exp2会转换为exp1,

下面看一下示例

SQL> select nvl('abc',123) from dual;
NVL('ABC',123)
--------------
abc

SQL> select nvl(123,'abc') from dual;
select nvl(123,'abc') from dual
ORA-01722: 无效数字

SQL> select nvl(123,'234') from dual;
NVL(123,'234')
--------------
           123

SQL> create table customers (cust_credit_limit number);
Table created

SQL> insert into customers values('1');
1 row inserted

SQL> insert into customers values('0.5');
1 row inserted

SQL> insert into customers values(null);
1 row inserted

SQL> commit;
Commit complete

SQL> SELECT NVL(cust_credit_limit,'Not Available') "NEW CREDIT" FROM customers;
SELECT NVL(cust_credit_limit,'Not Available') "NEW CREDIT" FROM customers
ORA-01722: 无效数字

SQL> SELECT NVL(cust_credit_limit,'88999') "NEW CREDIT" FROM customers;
NEW CREDIT
----------
         1
       0.5
     88999
SQL> 
但是如果没有数据的话,就会成功

SQL> SELECT NVL(cust_credit_limit,'Not Available') "NEW CREDIT" FROM customers;
NEW CREDIT
----------

SQL> 
这道题没有说有没有数据,就按有数据处理吧
A:错误,Not Available无法转换成number类型
B:错误,同上
C:错误,同上
D:正确,按照字符进行处理


你可能感兴趣的:(1z0-051)