Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: oracle date format model
tncc wrote:
> There is such a statement made by the oracle9i documentation (under Format
> model of SQL Reference):
> ***quote:***
> Oracle returns and error if an alphanumeric character is found in the date
> string where punctuation character is found in the format string. For
> example:
>
> TO_CHAR(TO_DATE('0297', 'MM/YY'), 'MM/YY')
>
> returns an error.
> *********
> However, I tried:
>
> select TO_CHAR(TO_DATE('0297', 'MM/YY'), 'MM/YY') from dual
>
> and there is no error returned. Instead the date is displayed properly
> (feb, 1997).
>
> What is meant by the above statement?
>
>
The doc also says the following, which explains why the example works, it looks like you have found a documentation inconsistency:
"The following additional formatting rules apply when converting string values to date values (unless you have used the FX or FXFM modifiers in the format model to control exact format checking):
" * You can omit punctuation included in the format string from the date string if all the digits of the numerical format elements, including leading zeros, are specified. In other words, specify 02 and not 2 for two-digit format elements such as MM, DD, and YY."
Example of the type of error the doc you found was warning against:
select TO_CHAR(TO_DATE('297', 'MM/YY'), 'MM/YY') from dual
*
Example where inexact format matching works OK:
select TO_CHAR(TO_DATE('2/97', 'MM/YY'), 'MM/YY') from dual;
TO_CHAR(TO_DATE('2/97','MM/YY'
-Mark Bole Received on Fri Dec 31 2004 - 18:03:09 CST