Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert string using TO_DATE when not all entries are in date format

mrbeanNov 1 2013 — edited Nov 4 2013

I have a string field where 99% of the entries are in a format that can be converted to a date, i.e. To_DATE(' 20100501', 'yyyymmdd') would work great. However, about 1% of the entries are in as something like '00000000' or '00000500'. So when I try to apply the TO_DATE function to all of the values, i.e. SELECT TO_DATE(datefield, 'yyyymmdd') the result is an error because the year or month is not valid for some of the entries. I am at a loss for what to do here. Perhaps I can make the TO_DATE function part of a sub query after a date validation has been applied? Maybe convert those non date formats to something like 19000101 to avoid the error???

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2013
Added on Nov 1 2013
4 comments
1,361 views