5

I always thought that to_date function string and date format should match. Why is the below statement working fine?

select TO_DATE('20151014','yyyy-mm-dd') from dual; 

Is oracle now ignoring the special characters before converting string to date?

This is in Oracle 11g.

spider8
  • 157
  • 1
  • 4
  • 13

1 Answers1

5

I found this interesting and asked the Google, which told me that basically when formats don't match Oracle tries it's hardest to make it work:

https://asktom.oracle.com/pls/apex/f?p=100:11:::NO:RP:P11_QUESTION_ID:9522299800346947976

http://www.oracledba.co.uk/tips/dates_8i.htm

You can use the 'FX' format string to make it match exactly:

http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements004.htm#r18c1-t65

http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements004.htm#SQLRF00216

You learn something new every day! Thanks for asking this!

Gary_W
  • 9,933
  • 1
  • 22
  • 40
  • Very interesting... I always thought that Oracle was very rigid with date formatting, compared to other RDBMSs. I guess you just have to know how to push its buttons. – Hambone Oct 22 '15 at 20:56
  • Same here. Very interesting. – Gary_W Oct 22 '15 at 20:57
  • I have also noticed this when I did something like 10-14-2015 when the date format actually called for 10/14/2015. This is good to know. – McGlothlin Oct 22 '15 at 21:02