将数字转换为日期 sql oracle
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31405833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert number to date sql oracle
提问by Dev_dev
I'm trying to convert a number (yyyymmdd
) to date (mm/dd/yyyy
)
我正在尝试将数字 ( yyyymmdd
)转换为日期 ( mm/dd/yyyy
)
For example
例如
20150302 ====> 03/02/2015
回答by Stefan Yordanov
You can try this:
你可以试试这个:
select to_date(20150302,'yyyymmdd') from dual;
or
或者
select to_char(to_date(20150302,'yyyymmdd'),'mm/dd/yyyy') from dual;
回答by Stanislovas Kala?nikovas
回答by Lalit Kumar B
TO_DATEaccepts char of CHAR
, VARCHAR2
, NCHAR
, or NVARCHAR2
datatype and converts into a value of DATEdatatype.
TO_DATE接受的炭CHAR
,VARCHAR2
,NCHAR
,或NVARCHAR2
的数据类型和转换成的数值DATE数据类型。
So, convert the number into string, and apply to_date. You could use single-quotation marksaround the number to convert it into string.
因此,将数字转换为字符串,并应用 to_date。您可以在数字周围使用单引号将其转换为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_CHARalong with your desired format model.
请记住,日期没有格式,您看到的只是用于显示目的。如果要以所需格式显示日期,请使用TO_CHAR和所需格式模型。
SELECT TO_CHAR(TO_DATE('20150302', 'YYYYMMDD'), 'mm/dd/yyyy') FROM dual;
Read more about TO_DATE.
阅读更多关于TO_DATE。