当前位置: 代码迷 >> Oracle认证考试 >> 关于to_date的有关问题
  详细解决方案

关于to_date的有关问题

热度:10109   发布时间:2013-02-26 00:00:00.0
关于to_date的问题!
Q: 90 For which two actions can you use the TO_DATE function? (Choose two.)

A. convert any date literal to a date
B. convert any numeric literal to a date
C. convert any date to a character literal
D. format 'January 10 1999' for input
E. format '10-JAN-99' to 'January 10 1999'

Answer: A, D

题目答案为什么是A D呢? B,C,E错在哪里呢?

------解决方案--------------------------------------------------------
感觉LZ都没看oracle入门的内容,上来就直接背题库。
------解决方案--------------------------------------------------------
我看你问的这几个问题,都是oracle的基础知识。稍稍看看书就能作答,你在这提问等人回答,不如翻翻书来的快。
------解决方案--------------------------------------------------------
TO_DATE 

1.转换一种时间格式为另外一种时间格式.
2.转换合法的时间字符串为时间.

例如:

SQL code
1.  MONTHS_BETWEEN with to_date function   SQL>SQL> SELECT MONTHS_BETWEEN(TO_DATE('22SEP2006','ddMONyyyy'),  2    TO_DATE('13OCT2001','ddMONyyyy')) "Months difference"  3  FROM dual;Months difference-----------------       59.2903226SQL>SQL>SQL>2.  Converting spelled date to DATE format   SQL>SQL> -- Converting spelled date to DATE format.SQL> SELECT TO_DATE('January 15','MONTH DD') "Sample" from DUAL;Sample---------15-JAN-06SQL>3.  Converting number representation to DATE format   SQL>SQL> -- Converting number representation to DATE format.SQL> SELECT TO_DATE('061167','MMDDYY') "Birthday" from DUAL;Birthday---------11-JUN-67SQL>4.  TO_CHAR(TO_DATE('04-JUL-15', 'DD-MON-YY'), 'DD-MON-YYYY')   SQL>SQL> SELECT TO_CHAR(TO_DATE('04-JUL-15', 'DD-MON-YY'), 'DD-MON-YYYY'),  2         TO_CHAR(TO_DATE('04-JUL-75', 'DD-MON-YY'), 'DD-MON-YYYY')  3  FROM dual;TO_CHAR(TO_ TO_CHAR(TO_----------- -----------04-JUL-2015 04-JUL-2075SQL>           5.  TO_DATE('04-JUL-15', 'DD-MON-RR'): Uses the RR format when interpreting the years 15 and 75 SQL>SQL> --Uses the RR format when interpreting the years 15 and 75SQL>SQL> SELECT  2    TO_CHAR(TO_DATE('04-JUL-15', 'DD-MON-RR'), 'DD-MON-YYYY'),  3    TO_CHAR(TO_DATE('04-JUL-75', 'DD-MON-RR'), 'DD-MON-YYYY')  4  FROM dual;TO_CHAR(TO_ TO_CHAR(TO_----------- -----------04-JUL-2015 04-JUL-1975SQL>
------解决方案--------------------------------------------------------
B. convert any numeric literal to a date 
numeric literal是字符化的数字,这里只有当数字与日期格式匹配才能正确转换,而不能是any

C. convert any date to a character literal 
只能用to_char把日期转换成文字

E. format '10-JAN-99' to 'January 10 1999' 
后面一个日期不是标准日期格式


------解决方案--------------------------------------------------------
探讨
B. convert any numeric literal to a date
numeric literal是字符化的数字,这里只有当数字与日期格式匹配才能正确转换,而不能是any

C. convert any date to a character literal
只能用to_char把日期转换成文字

E. format '10-JAN-99' to 'January 10 1999'
后面一个日期不是标准日期格式