Timestamp conversion in Oracle for YYYY-MM-DD HH:MM:SS format

本秂侑毒 提交于 2019-11-30 02:56:16

问题


I'm trying to insert records with YYYY-MM-DD HH:MM:SS format into Oracle from Netezza, but I'm getting invalid date type.

How can I accomplish this one?

CREATE TABLE AM_PROGRAM_TUNING_EVENT_TMP1
(
    ST TIMESTAMP,
    ET TIMESTAMP,
    MAS_DIV_KEY INTEGER NOT NULL,
    SBSC_GUID_KEY INTEGER NOT NULL,
    STN_KEY INTEGER NOT NULL
 );


INSERT INTO  AM_PROGRAM_TUNING_EVENT_TMP1 VALUES('2012-03-28 11:10:00','2012-03-28 11:30:00',1,3636815,151);

回答1:


INSERT INTO AM_PROGRAM_TUNING_EVENT_TMP1 
VALUES(TO_DATE('2012-03-28 11:10:00','yyyy/mm/dd hh24:mi:ss'));

http://www.sqlfiddle.com/#!4/22115/1




回答2:


Use TO_TIMESTAMP function

TO_TIMESTAMP(date_string,'YYYY-MM-DD HH24:MI:SS')


来源:https://stackoverflow.com/questions/10319935/timestamp-conversion-in-oracle-for-yyyy-mm-dd-hhmmss-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!