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?


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:正确,按照字符进行处理


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值