在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"')

评论(5)

嘿,我有同样的问题。我试图用TO_DATE('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS')将'2017-02-20 12:15:32'varchar转换为日期,但我收到的只是2017-02-20的时间消失了。

我的解决办法是使用TO_TIMESTAMP('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS')现在时间不会消失。

评论(1)

你可以使用铸成char来查看日期结果

评论(0)