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. EnableDocking

    CFrameWnd::EnableDocking void EnableDocking(DWORD dwDockStyle); 參数: dwDockStyle 指定框架窗体的哪一边可作为控件条的停靠点 ...

  2. RegexOptions.Compiled性能

    原文:http://www.cnblogs.com/me-sa/archive/2010/05/19/Is-RegexOptions-Compiled-a-Killer.html "使用正则 ...

  3. Property与Attribute的区别

    Property属于面向对象的范畴----属性 Attribute则是编程语言文法层面的东西----特征          Property属于面向对象的范畴.在使用面向对象编程的时候,常常需要对客观 ...

  4. Geodatabase - 打开要素类

    string dbPath = @"G:\doc\gis\1.400\data\pdb.mdb"; ESRI.ArcGIS.Geodatabase.IWorkspaceFactor ...

  5. oc随笔六:字典

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...

  6. 2、 Spark Streaming方式从socket中获取数据进行简单单词统计

    Spark 1.5.2 Spark Streaming 学习笔记和编程练习 Overview 概述 Spark Streaming is an extension of the core Spark ...

  7. hdu1520 第一道树形DP,激动哇咔咔!

    A - 树形dp Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  8. Linux下运行C++程序出现"段错误(核心已转储)"的原因

    今天写程序出现了“段错误(核心已转储)"的问题,查了一下资料,加上自己的实践,总结了以下几个方面的原因. 1.内存访问出错  这类问题的典型代表就是数组越界. 2.非法内存访问 出现这类问题 ...

  9. js中的function

    Math方法详解 Math.sqrt(x)    计算X开平方 Math.sqrt(x,y)   计算xy Math.round(x)   计算x 四舍五入的值 getBoundingClientRe ...

  10. 视差滚动(Parallax Scrolling)效果的原理与实现

    视差滚动(Parallax Scrolling)效果的原理与实现1.视差滚动效果的主要特点:    1)直观的设计,快速的响应速度,更合适运用于单页面    2)差异滚动 分层视差    页面上很多的 ...