89. You need to display the date 11-oct-2007 in words as 'Eleventh of October, Two Thousand Seven'.
Which SQL statement would give the required result?
A. SELECT TO_CHAR('11-oct-2007', 'fmDdspth "of" Month, Year')
FROM DUAL;
B. SELECT TO_CHAR(TO_DATE('11-oct-2007'), 'fmDdspth of month, year')
FROM DUAL;
C. SELECT TO_CHAR(TO_DATE('11-oct-2007'), 'fmDdthsp "of" Month, Year')
FROM DUAL;
D. SELECT TO_DATE(TO_CHAR('11-oct-2007','fmDdspth ''of'' Month, Year')) 错。
FROM DUAL;
Answer: C
答案解析:
A错误,'11-oct-2007'本来就是字符,就不用再to_char
B中'fmDdspth of month, year'的of需要用双引号引起来。
C正确。
D跟A一样的错误,'11-oct-2007'本来就是字符,就不用再to_char。
实验验证:
A,
scott@TEST0924> SELECT TO_CHAR('11-oct-2007', 'fmDdspth "of" Month, Year') FROM DUAL;
SELECT TO_CHAR('11-oct-2007', 'fmDdspth "of" Month, Year') FROM DUAL
*
ERROR at line 1:
ORA-01722: invalid number
B
scott@TEST0924> SELECT TO_CHAR(TO_DATE('11-oct-2007'), 'fmDdspth of month, year') FROM DUAL;
SELECT TO_CHAR(TO_DATE('11-oct-2007'), 'fmDdspth of month, year') FROM DUAL
*
ERROR at line 1:
ORA-01821: date format not recognized
C
scott@TEST0924> SELECT TO_CHAR(TO_DATE('11-oct-2007'), 'fmDdthsp "of" Month, Year') FROM DUAL;
TO_CHAR(TO_DATE('11-OCT-2007'),'FMDDTHS
---------------------------------------
Eleventh of October, Two Thousand Seven
D
scott@TEST0924> SELECT TO_DATE(TO_CHAR('11-oct-2007','fmDdspth ''of'' Month, Year')) FROM DUAL;
SELECT TO_DATE(TO_CHAR('11-oct-2007','fmDdspth ''of'' Month, Year')) FROM DUAL
*
ERROR at line 1:
ORA-01722: invalid number