SQL 将时间戳转换为数字格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23294562/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:44:01  来源:igfitidea点击:

Convert timestamp to number format

sqloracle

提问by JohnD

I have a timestampdatatype column (time_stamp_col) that stores data in the following format: 10-AUG-57 12.00.00.000000000 AM

我有一个timestamp数据类型列 ( time_stamp_col),它以以下格式存储数据: 10-AUG-57 12.00.00.000000000 AM

I need to convert it into a numberdatatype format like 19570810

我需要将其转换为number数据类型格式,如19570810

Any ideas? Thanks

有任何想法吗?谢谢

回答by D Stanley

Assuming your format is "YYYYMMDD", you should be able to use TO_CHARjust like a date field:

假设您的格式是"YYYYMMDD",您应该可以TO_CHAR像日期字段一样使用:

SELECT TO_NUMBER(TO_CHAR(time_stamp_col,'YYYYMMDD'))