大數(shù)據(jù)就業(yè)實戰(zhàn)培訓(xùn) Oracle就業(yè)實戰(zhàn)培訓(xùn)
071考試題庫之前是比較穩(wěn)定的,但隨著Oracle的調(diào)整,071考試不斷的增加新的考題,增加了考試的難度,所以我們專門收集整理了這些考試,并對這些考題進行解析,希望可以對考生有幫助。
每周五晚8點,我們有免費的OCP解析公開課,地址:https://ke.qq.com/course/326223 OCP題庫交流群:1015267481,驗證ocp
-------------------------------------------------------
071考試-第49題、choose the best answer
Examine the structure of the SHIPMENTS table:
You want to generate a report that displays the PO_ID and the penalty amount to be paid(罰款數(shù)額) if the SHIPMENT_DATE is later than one month from the PO_DATE. The penalty is $20 per day.
Evaluate the following two queries:
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) Only the second query executes successfully but gives a wrong result.
B) Only the second query executes successfully and gives the correct result.
C) Only the first query executes successfully but gives a wrong result.
D) Both execute successfully and give correct results.
E) Only the first query executes successfully and gives the correct result.
Answer:E
(解析:decode 函數(shù)的語法是,decode(條件,值 1,返回值 1,值 2,返回值 2,...值 n,返回值 n,缺省值),
所以不能有>1 的條件判斷。原來 051 的題。
該語句可以改寫為下面的語句:
SELECT empno,hiredate,
CASE
WHEN MONTHS_BETWEEN (sysdate,hiredate)>1
THEN TO_CHAR((sysdate - hiredate )*20)
ELSE 'No Penalty'
END PENALTY
FROM emp;)