Reputation: 57
In Oracle, I'm able to parse a string to a date type if the user input: dd/mm/yyyy. I would like to be able to parse without the slash: 01022012 should be parsed to 01/02/2012
a way is text processing and insert slash, then convert to date type. Is there another simple way? TNX
Upvotes: 1
Views: 1433
Reputation: 74605
TO_DATE doesn't require you to have any separating characters between your date parts. It might also be worth noting for your future reference that if the user input contains characters oracle doesn't care about (it only cares about date parts like dd, mm, yyyy) then they can be anything. All these work fine:
SELECT to_date('12/12/2012', 'dd/mm/yyyy') from dual
SELECT to_date('12-12-2012', 'dd/mm/yyyy') from dual
SELECT to_date('12@12;2012', 'dd#mm%yyyy') from dual
To_date doesn't insist that the separator characters and other ignored text in the date format picture shall match up with the ignored text in the input
Upvotes: 0
Reputation: 2113
select to_date('01022012','DDMMYYYY') from dual
==>
TO_DATE('01022012','DDMMYYYY')
------------------------------------
01-Feb-2012
-------- End of Data --------
1 row(s) fetched
Upvotes: 3