6. Examine the structure of the SHIPMENTS table:

name                    Null         Type

PO_ID               NOT NULL    NUMBER(3)

PO_DATE           NOT NULL    DATE

SHIPMENT_DATE    NOT NULL    DATE

SHIPMENT_MODE                 VARCHAR2(30)

SHIPMENT_COST                 NUMBER(8,2)

You want to generate a report that displays the PO_ID and the penalty amount to be paid if the

SHIPMENT_DATE is later than one month from the PO_DATE. The penalty is $20 per day.

Evaluate the following two queries:

(题意:题目给了一个发货表Shipments,当中有PO_DATE和SHIPMENT_DATE 字段,假设SHIPMENT_DATE比PO_DATE迟一个月,则每多一天罚款20,对此,请评价以下给出的两个sql语句)

SQL> SELECT po_id, CASE
WHEN MONTHS_BETWEEN (shipment_date,po_date)>1 THEN
TO_CHAR((shipment_date - po_date) * 20) ELSE 'No Penalty' END PENALTY
FROM shipments;

SQL>SELECT po_id, DECODE
(MONTHS_BETWEEN (po_date,shipment_date)>1,
TO_CHAR((shipment_date - po_date) * 20), 'No Penalty') PENALTY
FROM shipments;

Which statement is true regarding the above commands?

A. Both execute successfully and give correct results.

B. Only the first query executes successfully but gives a wrong result.

C. Only the first query executes successfully and gives the  correct result.

D. Only the second query executes successfully but gives a wrong result.

E. Only the second query executes successfully and gives the correct result.

Answer: C

decode函数的语法是,decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)

对照。上面decode使用错误。Case...When的语法是正确的,而且语句写的也是正确的,能够得到正确的结果。

第二个decode语法能够这样改,使用sign函数推断大小。

1 SELECT po_id, DECODE
2 (SIGN(MONTHS_BETWEEN(po_date,shipment_date)),1
3 TO_CHAR((shipment_date - po_date) * 20), 'No Penalty') PENALTY
4 FROM shipments;

OCP-1Z0-051-题目解析-第6题的更多相关文章

  1. 1Z0-053 争议题目解析

    1Z0-053 争议题目解析 Summary 题目NO. 题目解析链接地址 题库答案 参考答案 考查知识点  24 http://www.cnblogs.com/jyzhao/p/5319220.ht ...

  2. 1Z0-053 争议题目解析25

    1Z0-053 争议题目解析25 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 25.You enabled Flashback Data Archive on the INVEN ...

  3. 1Z0-053 争议题目解析24

    1Z0-053 争议题目解析24 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 24.Which of the following information will be gath ...

  4. 1Z0-053 争议题目解析46

    1Z0-053 争议题目解析46 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 46.What happens when you run the SQL Tuning Adviso ...

  5. 1Z0-053 争议题目解析86

    1Z0-053 争议题目解析86 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 86.Your production database is running in archivel ...

  6. 1Z0-053 争议题目解析134

    1Z0-053 争议题目解析134 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 134.You are managing an Oracle Database 11g datab ...

  7. 1Z0-053 争议题目解析154

    1Z0-053 争议题目解析154 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 154.A database is running in ARCHIVELOG mode and ...

  8. 1Z0-053 争议题目解析175

    1Z0-053 争议题目解析175 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 175.You are peer reviewing a fellow DBAs backup p ...

  9. 1Z0-053 争议题目解析212

    1Z0-053 争议题目解析212 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 212.Note the following parameters settings in you ...

  10. 1Z0-053 争议题目解析304

    1Z0-053 争议题目解析304 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 304.What privileges must be granted to allow an a ...

随机推荐

  1. HDU 2845 Beans (DP)

    Problem Description Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled ...

  2. JMeter简单性能测试(适合初学者)

    利用JMeter进行Web测试     JMeter介绍    脚本录制    运行JMeter进行测试    JMeter主要组件介绍    参数化设置    动态数据关联    使用命令行运行JM ...

  3. magento xml配置详解

    <?XML版本=“1.0”? <config> <节> 实施例translate="label"> <label>的一个例子< ...

  4. discuzx3.2伪静态

    首先,我们要新建一个名为.htaccess的文件,文件名为空白,这点很重要.很多人无法新建这个文件,在这里教大家如何新建没有名字的文件. 新建一个TXT文本,名字先默认.然后打开这个文本,然后把我们的 ...

  5. Gradle 编译时选择不同的 google-services.json

    在做的安卓应用需要在 debug 和 release build中使用不同的谷歌服务账号,要用到不同的google-serivces.json ,手动替换的话太费时费力,好在万能的gradle可以完成 ...

  6. 《第一行代码》学习笔记14-UI(3)

    1. (1)所有控件都是直接或间接继承自View,所用的所有布局都是直接或间接继承自ViewGroup的. (2)View是Android中一种最基本的UI组件,可以在屏幕上绘制一块矩形区域,并能响应 ...

  7. Oracle游标cursor2显示的游标等

    --在一中我们介绍了实现过程 select *from stud; declare cursor mycur is select id,name from stud;--1声明 v_id intege ...

  8. js-浏览器DOM

    1.window尺寸 适配所有浏览器的尺寸方案 var w=window.innerWidth|| document.documentElement.clientWidth|| document.bo ...

  9. oracle数据库ID自增长

    使用sequence --创建sequenceCREATE SEQUENCE emp_sequence      INCREMENT BY 1  -- 每次加几个      START WITH 1  ...

  10. struts2 result的type属性

    目前只使用过以下3种,都是直接跳转到另一个action  chain: 写法:<result name="success" type="chain"> ...