I have a field in a table that can be informed with differente values. Examples:
Row 1 - (2012,2013)
Row 2 - 8871
Row 3 - 01/04/2012
Row 4 - 'NULL'
I have to identify the rows that have a string with a date mask 'dd/mm/yyyy' informed. Like Row 3, so I may add a TO_DATE function to it.
Any idea on how can I search a mask within the field?
Thanks a lot
SQL Fiddle
Oracle 11g R2 Schema Setup:
Query 1 - You can check with a regular expression:
Results:
Query 2 - You can make the regular expression more complicated to catch more invalid dates:
Results:
Query 3 - But the best way is to try and convert the value to a date and see if there is an exception:
Results:
Sounds like a data model problem (storing a date in a string).
But, since it happens and we sometimes can't control or change things, I usually keep a function around like this one:
Then use it like this:
You can use the like operator to match the pattern.
where possible_date_field like
'__/__/____'
;