簡體   English   中英

在 Oracle 中將字符串日期轉換為日期時間

[英]Convert a string date into datetime in Oracle

如何在 oracle 中將此字符串日期轉換為日期時間。

2011-07-28T23:54:14Z

使用此代碼會引發錯誤:

TO_DATE('2011-07-28T23:54:14Z',  'YYYY-MM-DD HH24:MI:SS')

如何才能做到這一點?

Error report:
SQL Error: ORA-01861: literal does not match format string
01861. 00000 -  "literal does not match format string"
*Cause:    Literals in the input must be the same length as literals in
           the format string (with the exception of leading whitespace).  If the
           "FX" modifier has been toggled on, the literal must match exactly,
           with no extra whitespace.
*Action:   Correct the format string to match the literal.

更新:-

TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')

我只看到列中的日期而不是時間

28-JUL-11

試試這個: TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')

嘿我有同樣的問題。 我試圖將 '2017-02-20 12:15:32' varchar 轉換為TO_DATE('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS')和我收到的只是 2017-02-20 時間消失了

我的解決方案是使用TO_TIMESTAMP('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS')現在時間不會消失。

您可以使用強制轉換為字符來查看日期結果

 select to_char(to_date('17-MAR-17 06.04.54','dd-MON-yy hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') from dual;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM