TO_TIMESTAMP ('20151206 00:00:00', 'yyyymmdd hh: mm: ss')
This is wrong in two ways:
1. Invalid code format
You repeated the mask in MM format twice. MM month and MI minutes .
SQL> SELECT TO_TIMESTAMP ('20151206 00:00:00', 'yyyymmdd hh: mm: ss') FROM dual;
SELECT TO_TIMESTAMP ('20151206 00:00:00', 'yyyymmdd hh: mm: ss') FROM dual
*
ERROR at line 1:
ORA-01810: format code appears twice
2. Incorrect part of time
00:00:00 incorrect because it throws ORA-01849 , since the hour cannot be zero, it must be from 1 to 12.
SQL> SELECT TO_TIMESTAMP ('20151206 00:00:00', 'yyyymmdd hh: mi: ss') FROM dual;
SELECT TO_TIMESTAMP ('20151206 00:00:00', 'yyyymmdd hh: mi: ss') FROM dual
*
ERROR at line 1:
ORA-01849: hour must be between 1 and 12
The correct way is to either use the 24-hour format or leave a fraction of the time , which is 12 AM by default.
For instance,
24 hour format:
SQL> SELECT TO_TIMESTAMP('20151206 00:00:00', 'yyyymmdd hh24:mi:ss') my_tmstamp FROM dual; MY_TMSTAMP --------------------------------------------------------------------------- 06-DEC-15 12.00.00.000000000 AM
No time:
SQL> SELECT TO_TIMESTAMP('20151206', 'yyyymmdd') my_tmstamp FROM dual; MY_TMSTAMP ----------------------------------------------------------------------- 06-DEC-15 12.00.00.000000000 AM
source share