[每日一题] OCP1z0-047 :2013-08-10 INTERVAL DAY TO SECOND(一)

2014-11-24 14:59:27 · 作者: · 浏览: 0
[每日一题] OCP1z0-047 :2013-08-10 INTERVAL DAY TO SECOND
正解答案是:B
“根据题意要求,需要存储的是一个时间间隔的数据,且方便加减,所以首先排除timestamp类型。然后题目要求最大的周期是30天,所以year to month排除,因为该项只能精确到月。然后就剩下B“
官方文档解释:
INTERVAL YEAR TO MONTH Datatype
INTERVAL YEAR TO MONTH stores a period of time using theYEAR andMONTH datetime fields. This datatype is useful for representing the differencebetween two datetime values when only the year and month values aresignificant.
Specify INTERVAL YEAR TO MONTH as follows:
INTERVAL YEAR [(year_precision)] TO MONTH
Datetime and Interval Examples
The following example shows how to declare some datetimeand interval datatypes.
[html] 
hr@MYDB> hr@MYDB> SELECT last_name, sysdate,hire_date,EXTRACT(YEAR FROM (SYSDATE - hire_date) YEAR TO MONTH )  
  2     || ' years '  
  3     || EXTRACT(MONTH FROM (SYSDATE - hire_date) YEAR TO MONTH )  
  4     || ' months'  "Interval"  
  5  FROM employees ;  
  
LAST_NAME                 SYSDATE      HIRE_DATE    Interval  
------------------------- ------------ ------------ --------------------------------------------------  
Dilly                     10-AUG-13    13-AUG-05    8 years 0 months  
Gates                     10-AUG-13    11-JUL-06    7 years 1 months  
Perkins                   10-AUG-13    19-DEC-07    5 years 8 months  
Bell                      10-AUG-13    04-FEB-04    9 years 6 months中间结果省略  
Bull                      10-AUG-13    20-FEB-05    8 years 6 months  
Dellinger                 10-AUG-13    24-JUN-06    7 years 2 months  
Cabrio                    10-AUG-13    07-FEB-07    6 years 6 months  
Chung                     10-AUG-13    14-JUN-05    8 years 2 months  
  
107 rows selected.  

INTERVAL DAY TO SECOND Datatype
INTERVAL DAY TO SECOND stores a period of time in terms of days, hours, minutes, and seconds.This datatype is useful for representing the precise difference between twodatetime values.
Specify this datatype as follows:
INTERVAL DAY [(day_precision)] 
   TO SECOND [(fractional_seconds_precision)]


TIMESTAMP WITH TIME ZONE Datatype
TIMESTAMP WITH TIME ZONE is a variant ofTIMESTAMP that includes a time zoneoffset in its value. The time zone offset is the difference (in hoursand minutes) between local time and UTC (Coordinated Universal Time—formerlyGreenwich Mean Time). This datatype is useful for collecting and eva luatingdate information across geographic regions.
Specify the TIMESTAMP WITH TIME ZONE datatype as follows:
TIMESTAMP [(fractional_seconds_precision)] WITH TIME ZONE

[html] 
oe@MYDB> col ORDER_DATE for a30  
oe@MYDB> col Interval for a30  
oe@MYDB> SELECT order_id,sysdate,order_date,  
  2     EXTRACT(DAY FROM (SYSDATE - order_date) DAY TO SECOND )  
  3     || ' days '  
  4     || EXTRACT(HOUR FROM (SYSDATE - order_date) DAY TO SECOND )  
  5     || ' hours' "Interval"  
  6  FROM orders;  
  
  ORDER_ID SYSDATE      ORDER_DATE                     Interval  
---------- ------------ ------------------------------ ------------------------------  
2442 10-AUG-13    28-JUL-90 02.22.59.662632 AM   8414 days 21 hours  
2443 10-AUG-13    28-JUL-90 03.34.16.562632 AM   8414 days 20 hours  
2445 10-AUG-13    28-JUL-90 05.34.38.362632 AM   8414 days 18 hours  
2418 10-AUG-13    21-MAR-96 08.18.21.862632 AM   6351 days 15 hours 2415 10-AUG-13    30-MAR-97 05.34.50.545196 AM   5977 days 18 hours  
2357 10-AUG-13    09-JAN-98 12.19.44.123456 PM   5692 days 11 hours  

省略中间结果
2447 10-AUG-13 27-JUL-00 10.59.10.223344 PM 4762 days 0 hours
2441 10-AUG-13 02-AUG-00 01.22.48.734526 AM 4756 days 22 hours
13 10-AUG-13 04-AUG-13 09.32.52.000000 PM 6 days 2 hours
130 10-AUG-13 04-AUG-13 10.55.36.000000 PM 6 days 0 hours
107 rows selected.