问题
I'm trying to convert a number (yyyymmdd) to date (mm/dd/yyyy)
For example
20150302 ====> 03/02/2015
回答1:
You can try this:
select to_date(20150302,'yyyymmdd') from dual;
or
select to_char(to_date(20150302,'yyyymmdd'),'mm/dd/yyyy') from dual;
回答2:
You can use TO_DATE function to convert NUMBER to DATE. Try in following:
SELECT TO_DATE(20150302, 'YYYYMMDD') FROM DUAL
回答3:
TO_DATE accepts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype and converts into a value of DATE datatype.
So, convert the number into string, and apply to_date. You could use single-quotation marks around the number to convert it into string.
SELECT TO_DATE('20150302', 'YYYYMMDD') FROM dual;
Remember, a DATE has no format, what you see is for display purpose. If you want to display the date in a desired format, then use TO_CHAR along with your desired format model.
SELECT TO_CHAR(TO_DATE('20150302', 'YYYYMMDD'), 'mm/dd/yyyy') FROM dual;
Read more about TO_DATE.
来源:https://stackoverflow.com/questions/31405833/convert-number-to-date-sql-oracle