OCP-1Z0-051 第102题 TO_DATE,TO_CHAR,TO_NUMBER函数的用法

一、原题
Examine the structure of the TRANSACTIONS table:)
Name            Null            Type
TRANS_ID        NOT NULL        NUMBER(3)
CUST_NAME                       VARCHAR2(30)
TRANS_DATE                      TIMESTAMP
TRANS_AMT                       NUMBER(10,2)
You want to display the date, time, and transaction amount of transactions that where done before 12 noon. The value zero should be displayed for transactions where the transaction amount has not been entered.
Which query gives the required result?
A. SELECT TO_CHAR(trans_date,'dd-mon-yyyy hh24:mi:ss'),
                    TO_CHAR(trans_amt,'$99999999D99')
        FROM transactions
     WHERE TO_NUMBER(TO_DATE(trans_date,'hh24')) < 12 
          AND COALESCE(trans_amt,NULL)<>NULL;

B. SELECT TO_CHAR(trans_date,'dd-mon-yyyy hh24:mi:ss'),
                    NVL(TO_CHAR(trans_amt,'$99999999D99'),0)
        FROM transactions
     WHERE TO_CHAR(trans_date,'hh24') < 12;

C. SELECT TO_CHAR(trans_date,'dd-mon-yyyy hh24:mi:ss'),
                    COALESCE(TO_NUMBER(trans_amt,'$99999999.99'),0)
        FROM transactions
      WHERE TO_DATE(trans_date,'hh24') < 12;

D. SELECT TO_DATE (trans_date,'dd-mon-yyyy hh24:mi:ss'),
                    NVL2(trans_amt,TO_NUMBER(trans_amt,'$99999999.99'), 0)
        FROM transactions
     WHERE TO_DATE(trans_date,'hh24') < 12;

答案:B

二、题目翻译
查看表结构
要显示在中午12点之前完成的交易的日期、时间和数量。如果transaction数量没有值则显示0。
哪一个查询给出所需结果?

三、题目解析
A选项不正确,WHERE条条中,应该是to_char,不是to_date
CD选项不正确,trans_amt是number类型,TO_NUMBER函数转换会出错。
NVL和NULLIF,COALESCE的用法,详见:
         http://blog.csdn.net/holly2008/article/details/25251513

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值