SQL oracle如何将日期保存为24小时格式

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

How to save date into 24 hours format in oracle

sqloracleoracle10g

提问by laxmanperamalla

I am new to Oracle, and I need to save date and time in an Oracle database.

我是 Oracle 的新手,我需要在 Oracle 数据库中保存日期和时间。

I am using time stamp as datatype for row. But now my problem is it saves date and time in 12 hours format like this 17/11/2011 10:10:10 PM.

我使用时间戳作为行的数据类型。但现在我的问题是它像这样以 12 小时格式保存日期和时间17/11/2011 10:10:10 PM

But I need it in 24 hours format like 17/11/2011 22:10:10. I didn't understand the results that Google search result provided. Can any one please help me by posting some code.

但我需要 24 小时格式,如17/11/2011 22:10:10. 我不明白 Google 搜索结果提供的结果。任何人都可以通过发布一些代码来帮助我。

回答by Justin Cave

Oracle always stores timestamps (and dates) in a packed binary format that is not human readable. Formatting is done only when a timestamp (or a date) is converted to a string.

Oracle 始终以人类不可读的打包二进制格式存储时间戳(和日期)。仅当时间戳(或日期)转换为字符串时才会进行格式化。

You can control the formatting of your output by coding an explicit to_char. For example

您可以通过编码显式to_char. 例如

SELECT to_char( your_timestamp_column, 'DD/MM/YYYY HH24:MI:SS' ) 
  FROM your_table

回答by Martijn

Oracle stores timestamps in an internal format (with a default representation).

Oracle 以内部格式(具有默认表示)存储时间戳。

You can customize this representation on output like with the to_char()function.

您可以像使用to_char()函数一样在输出上自定义此表示。

For input (into the database) you can use to_date().

对于输入(进入数据库),您可以使用to_date().