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

来源:互联网 发布:如何看淘宝价格曲线 编辑:程序博客网 时间:2024/06/05 06:19
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;
答案:D
这道题其实主要考察nvl函数参数类型的问题,nvl(exp1,exp2),如果exp1为null那么返回exp2,
exp1和exp2类型必须相同,如果不相同那么系统会将exp2会转换为exp1,

下面看一下示例

SQL> select nvl('abc',123) from dual;NVL('ABC',123)--------------abcSQL> select nvl(123,'abc') from dual;select nvl(123,'abc') from dualORA-01722: 无效数字SQL> select nvl(123,'234') from dual;NVL(123,'234')--------------           123SQL> create table customers (cust_credit_limit number);Table createdSQL> insert into customers values('1');1 row insertedSQL> insert into customers values('0.5');1 row insertedSQL> insert into customers values(null);1 row insertedSQL> commit;Commit completeSQL> SELECT NVL(cust_credit_limit,'Not Available') "NEW CREDIT" FROM customers;SELECT NVL(cust_credit_limit,'Not Available') "NEW CREDIT" FROM customersORA-01722: 无效数字SQL> SELECT NVL(cust_credit_limit,'88999') "NEW CREDIT" FROM customers;NEW CREDIT----------         1       0.5     88999SQL> 
但是如果没有数据的话,就会成功

SQL> SELECT NVL(cust_credit_limit,'Not Available') "NEW CREDIT" FROM customers;NEW CREDIT----------SQL> 
这道题没有说有没有数据,就按有数据处理吧
A:错误,Not Available无法转换成number类型
B:错误,同上
C:错误,同上
D:正确,按照字符进行处理


0 0
原创粉丝点击