如何在 oracle 中将日期转换为时间戳(DD-MON-YYYY HH24:MI:SS.FF 格式)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34329483/
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
How to convert date to timestamp(DD-MON-YYYY HH24:MI:SS.FF format) in oracle?
提问by Mizanur Rahman Milon
I tried below query but its not working
我试过下面的查询,但它不工作
select
TO_TIMESTAMP(ColumnName(Data type Date), 'DD-MON-YYYYHH24:MI:SS.FF')
from TableName
where Changedate>='01-Dec-2015'
*I need the result without AM/PM indication. Result will be 15-DEC-2015 15:16:42.045016
*我需要没有 AM/PM 指示的结果。结果将是 15-DEC-2015 15:16:42.045016
采纳答案by hol
If I got your question right you need the output in the mentioned Format. That would be a conversion to character
如果我问对了你的问题,你需要上述格式的输出。那将是对字符的转换
select to_char(cast(sysdate as timestamp),'DD-MON-YYYY HH24:MI:SS.FF') from dual
Of course in the above the FF would also always be 000000
当然在上面的FF也总是000000
But if you have a timestamp variable you would not cast
但是如果你有一个时间戳变量,你就不会强制转换
select to_char(systimestamp,'DD-MON-YYYY HH24:MI:SS.FF') from dual
回答by Dinidu Hewage
select to_char(cast(sysdate as timestamp),'DD-MON-YYYY HH24:MI:SS') from dual
回答by akanksha gupta
These are 2 ways you can try:
您可以尝试以下两种方法:
to_char(cast(sysdate as timestamp), 'YYYY-MM-DD HH:MM:SS.ff')
or:
或者:
to_char(to_Date(sysdate, 'DD-MON-YY'), 'YYYY-MM-DD HH:MM:SS')
回答by Durga Viswanath Gadiraju
I think you need not have to convert to timestamp if your column is of date data type. Also there is no need to use .FF as date will not have time in milliseconds.
如果您的列是日期数据类型,我认为您不必转换为时间戳。也没有必要使用 .FF 因为日期没有以毫秒为单位的时间。
select to_char(ColumnName(Data type Date), 'DD-MON-YYYYHH24:MI:SS.FF') from dual;