ORA-01839 date not valid for month specified error message
Okay, the challenge is to try and describe my issue clearly.
I am wanting to write an SQL statement and in that statement I am needing to compare the value of a character field to a date field. The WHERE clause that I am specifically doing includes the following -
TO_DATE(bv1.version_name,'MM/DD/YYYY') <= wip.pa_date
VERSION_NAME is my character column/field. It is intended to hold a date type value, in the specified format (for example, a value = '05/31/2010'). Of course this being the real world and an alpha field, the contents of this column often don't match the desired format. So I added some more stuff to the WHERE clause -
bv1.version_name LIKE '__/__/____' AND bv1.version_name BETWEEN '01/%' AND '12/%'
That took care of most of my problems. However I still run into an occasional ORA-01839 error. I do understand why. I still have a few goofy values in the table. For example, I may have a row where version_name = '02/29/2009'. That value meets my desired format, and the month is between 01 and 12, but that clearly is not a valid date. Of course some Februaries day 29 is a valid day. So I don't want try and do something like BETWEEN '02/01%' AND '02/28%', as then I may eliminate a good record.
So here is my question - is there any way to work around this kind of situation? Either bypass the row in error, or somehow convert that bad date value to say the last day of the month? I have been reading through the Oracle SQL manual, but not finding anything that talks about this kind of situation (just may not have found the right place yet). I would think that when you have a function to convert a character value to a date value, that there would be something to handle this kind of situation, but maybe there is not. I could hard wire an edit for specific dates, but since I want this to be a SCRIPT to build a summary table, I don't want to have to keep checking to see if I need to modify the script. So looking for something that would automatically handle this situation.
I hope this makes sense. If any questions or need more information, let me know. Thanks for your time and assistance.
John Dickey