博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OCP-1Z0-051-题目解析-第6题
阅读量:5025 次
发布时间:2019-06-12

本文共 1603 字,大约阅读时间需要 5 分钟。

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, CASEWHEN MONTHS_BETWEEN (shipment_date,po_date)>1 THENTO_CHAR((shipment_date - po_date) * 20) ELSE 'No Penalty' END PENALTYFROM 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, DECODE2 (SIGN(MONTHS_BETWEEN(po_date,shipment_date)),1 3 TO_CHAR((shipment_date - po_date) * 20), 'No Penalty') PENALTY4 FROM shipments;

 

转载于:https://www.cnblogs.com/mengfanrong/p/5231260.html

你可能感兴趣的文章
连接Linux下 XAMPP集成环境中部署的禅道的数据库MariaDB
查看>>
Java操作Excel和Word
查看>>
Oracle 体系结构之ORACLE物理结构
查看>>
ORA-12538: TNS: no such protocol adapter
查看>>
盒子模型
查看>>
局域网协议
查看>>
[HNOI2012]永无乡 线段树合并
查看>>
Spring整合hibernate:3、使用XML进行声明式的事务管理
查看>>
SqlServer之Convert 函数应用格式化日期(转)
查看>>
软件测试领域中的10个生存和发展技巧
查看>>
Camera前后摄像头同时预览
查看>>
HDU 1856
查看>>
课堂作业01--架构师的职责
查看>>
iOS计算富文本(NSMutableAttributedString)高度
查看>>
2017/09/15 ( 框架2)
查看>>
三、模版的使用
查看>>
hihoCoder 1174 拓扑排序·一
查看>>
git 的更新代码的取消
查看>>
UVA - 1103 Ancient Messages
查看>>
《数据挖掘与数据化运营实战 思路、方法、技巧与应用》—— 读书笔记
查看>>