web-dev-qa-db-ja.com

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
20
arsenal

これを試してください:TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')

43

ちょっと同じ問題があった。 '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')を使用することでした。今は時間が消えません。

1
Sebastian Biner

Charへのキャストを使用して、日付の結果を表示できます

 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;
0
Denisjc