1

I'm trying to create a date subtract two days and then convert it to a char. For some reason I'm getting the following error:

ORA-01830: date format picture ends before converting entire input string

Here's my code:

 SELECT TO_CHAR(to_date('20-JUL-01 10:40:12')-2, 'dd-Mon-yy 24HH:MI:SS') as "Subtract 2 Days"
       FROM DUAL;

I'm not sure what's wrong, it seems to be an issue with the seconds

4

1 回答 1

5

Oracle 默认为上午/下午的 12 小时制。因此,您需要一个日期格式来进行日期转换:

SELECT TO_CHAR(to_date('20-JUL-01 10:40:12', 'dd-Mon-yy HH24:MI:SS')-2,
               'dd-Mon-yy HH24:MI:SS') as "Subtract 2 Days"
FROM DUAL;

此外,正确的 24 小时符号是“HH24”,而不是“24HH”。

于 2016-03-09T16:13:51.490 回答