SQL 如何格式化时间戳

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

How To Format Timestamp

sqloracleplsql

提问by Avi

I have col1in myTablewhich is varchar, and I have to insert here timestamp eg:- 09-MAY-11 10.23.12.0000 AM.

col1myTablewhich is 中varchar,我必须在此处插入时间戳,例如:- 09-MAY-11 10.23.12.0000 AM

Now please tell me:

现在请告诉我:

  • How to insert into myTable with taking sysdate in above format...
  • How to retrieve data from col1 in tha same timestamp format..
  • 如何使用上述格式的 sysdate 插入到 myTable 中...
  • 如何以相同的时间戳格式从 col1 检索数据..

回答by schurik

INSERT:

插入:

insert into myTable (col1) VALUES (to_char(systimestamp, 'dd-mon-yyyy hh.mi.ss.ff4 AM') );

SELECT:

选择:

select to_timestamp(col1, 'dd-mon-yyyy hh.mi.ss.ff4 AM')  from myTable ;

But it is much better to store the data directly as a timestamp. Then you can compare the values ??or modify them directly.

但是将数据直接存储为时间戳要好得多。然后你可以比较这些值??或者直接修改它们。

create table myTable1( col1 timestamp default systimestamp);