OCP-1Z0-051-题目解析-第6题

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题

时间: 2024-11-20 09:48:41

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

Oracle OCP 11G 051(61题版本)答案解析目录

Oracle OCP 11G 051(61题版本)答案解析目录 61题版本 V9.02 1 http://blog.csdn.net/rlhua/article/details/17635843 2  http://blog.csdn.net/rlhua/article/details/17635887 3 http://blog.csdn.net/rlhua/article/details/17635919 86 4 http://blog.csdn.net/rlhua/article/det

英雄会题目解析- 第五届在线编程大赛月赛第三题:石子游戏

题目: 甲乙两人面对若干堆石子,其中每一堆石子的数目可以任意确定.两人轮流按下列规则取走一些石子,游戏的规则如下:1.每一步应取走至少一枚石子:2.每一步只能从某一堆中取走部分或全部石子:3.如果谁无法按规则取子,谁就是输家.如果甲乙两人都采取最优的策略,甲先拿,请问,是甲必胜还是乙必胜.输入格式:多组数据,每组数据两行,第一行是一个整数N, 2<=N<=10000下一行是N个正整数,代表每堆的石子数,石子数在32位整数内.输出格式:每组测试数据输出一行,如果甲存在必胜策略,输出"W

OCP-1Z0-051-题目解析-第10题

10. View the Exhibit and examine the structure of the PROMOTIONS table. Each promotion has a duration of at least seven days . Your manager has asked you to generate a report, which provides the weekly cost for each promotion done to l date. Which qu

增量备份,11g052题目解析

增量备份分为差异备份(differential incremental backup)和累积备份(cumulative incremental backup),这是两种执行增量备份操作的不同方法. 80. You perform differential incremental level 1 backups of your database on each working day and level 0 backup on Sundays, to tape. Which two stateme

OCP-1Z0-051-题目解析-第11题

11. View the Exhibit and examine the structure of the PRODUCTS table.All products have a list price. You issue the following command to display the total price of each product after a discount of 25% and a tax of 15% are  applied on it. Freight charg

OCP-1Z0-051-题目解析-第1题

1. View the Exhibit and examine the structure of the SALES, CUSTOMERS, PRODUCTS, and TIMES tables. The PROD_ID column is the foreign key in the SALES table, which references the PRODUCTS table. Similarly, the CUST_ID and TIME_ID columns are also fore

Oracle OCP认证考试题库解析052-1&2

QUESTION 1 You notice that the performance of the database has degraded because of frequent checkpoints. Which two actions resolve the issue? (Choose two.) A. Disable automatic checkpoint tuning B. Check the size of the redo log file size and increas

OCP-1Z0-051-题目解析-第12题

12. You need to produce a report where each customer's credit limit has been incremented by $1000. Inthe output, the customer's last name should have the heading Name and the incremented credit limitshould be labeled New Credit Limit. The column head

OCP-1Z0-051-题目解析-第3题

3. You need to extract details of those products in the SALES table where the PROD_ID columncontains the string '_D123'.Which WHERE clause could be used in the SELECT statement to get the required output?A. WHERE prod_id LIKE '%_D123%' ESCAPE '_'B. W

OCP-1Z0-051-题目解析-第4题

4. Which two statements are true regarding single row functions? (Choose two.) A. They a ccept only a single argument. B. They can be nested only to two levels. C. Arguments can only be column values or constants. D. They a lways return a single resu