将 oracle 日期字符串转换为数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14816916/
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 oracle date string to number
提问by user1050619
I need to convert a date string -'2013-01-01' to number --20130101 type..How can I accomplish it in Oracle efficiently?
我需要将日期字符串 -'2013-01-01' 转换为数字 --20130101 类型..如何在 Oracle 中有效地完成它?
My Input-
'2013-01-01'
My Output
Output-20130101
回答by GriffeyDog
select to_number(replace('2013-01-01', '-')) from dual;
回答by Fabio Farath
You can convert the string to date and convert back using the format that you want to:
您可以将字符串转换为日期并使用您想要的格式转换回来:
select to_char(to_date('2013-01-01', 'YYYY-MM-DD'), 'YYYYMMDD');
More information about datetime format:
有关日期时间格式的更多信息:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm
回答by Plouf
to_char(your_date,'YYYYMMDD')
Just the basics of using to_char with a date here.
只是在这里使用带有日期的 to_char 的基础知识。
回答by A.B.Cade
You can also "exploit" the format mask:
您还可以“利用”格式掩码:
select to_number('2013-01-01', '9999G99G99', 'nls_numeric_characters=,-')
from dual