在 oracle 时间戳列中插入时间戳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12390606/
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
Inserting timestamp in oracle timestamp column
提问by Anand
I have a table in which there is a column with datatype TIMESTAMP(0)
我有一个表,其中有一列数据类型 TIMESTAMP(0)
When I insert a date into this column using
当我使用
INSERT INTO TEST_TIMESTAMP VALUES(SYSDATE)
it inserts a date in the following example format
它以以下示例格式插入日期
12-SEP-12 10.31.19.000000000 AM
12-SEP-12 10.31.19.000000000 AM
I want to know how the below timestamp formats can be inserted in the table
我想知道如何在表中插入以下时间戳格式
12-SEP-12 10.31.19
and 12-SEP-12 10.31.19 AM
12-SEP-12 10.31.19
和 12-SEP-12 10.31.19 AM
I tried specifying some formats using TO_CHAR
while inserting SYSDATE
into the table, but it didn't work.
我尝试TO_CHAR
在插入SYSDATE
表格时指定一些格式,但没有用。
Please suggest.
请建议。
回答by paul
when you store a TIMESTAMP
it will always store the data at maximum precision (with fractional seconds).
当您存储 a 时TIMESTAMP
,它将始终以最大精度(小数秒)存储数据。
I think what you want to do is supply a format to display the date when you retrieve it from the database.
我认为您想要做的是提供一种格式以在您从数据库中检索日期时显示日期。
You can do this like so:
你可以这样做:
select to_char(timestampColumnName,'DD-MON-YY HH24:MI:SS') "Date" from test_timestamp
or
或者
select to_char(timestampColumnName,'DD-MON-YY HH:MI:SS AM') "Date" from test_timestamp
回答by Drogu
You can return it very easy like:
您可以非常轻松地返回它,例如:
SELECT to_char(sysdate,'DD-MON-YY HH24:MI:SS') FROM DUAL;
In your case use:
INSERT INTO TEST_TIMESTAMP(column_name) VALUES(to_char(sysdate,'DD-MON-YY HH24:MI:SS'));
SELECT to_char(sysdate,'DD-MON-YY HH24:MI:SS') FROM DUAL;
在你的情况下使用:
INSERT INTO TEST_TIMESTAMP(column_name) VALUES(to_char(sysdate,'DD-MON-YY HH24:MI:SS'));
回答by da_kong
You were missing the extra ().
你错过了额外的 ()。
INSERT INTO TEST_TIMESTAMP
VALUES (TO_TIMESTAMP('12-SEP-12 10.31.19', 'DD-MON-YY HH.MI.SS'));
INSERT INTO TEST_TIMESTAMP
VALUES (TO_TIMESTAMP('12-SEP-12 10.31.19 AM', 'DD-MON-YY HH.MI.SS AM'));
回答by Juan hernan jaime arias
TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS')
This for colum type insert over mode to_char
.
这用于列类型插入模式to_char
。