I am executing this query and getting this error. Please help.
SQL> select to_timestamp((sysdate-1)||'01.00.00.000000000 PM','DD-MON-RR HH.MI.SS.FF PM') from dual;
ERROR at line 1: ORA-01855: AM/AM or PM/PM required
When you use sysdate
without explicit casting, you assume that you NLS settings give a date in format 'DD-MON-RR'
. To build a safer query, use explicit conversion, with format mask:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> select to_timestamp(to_char(sysdate-1,'DD-MON-RR' ) ||' 01.00.00.000000000 PM','DD-MON-RR HH.MI.SS.FF PM') from dual;
TO_TIMESTAMP(TO_CHAR(SYSDATE-1,'DD-MON-RR')||'01.00.00.000000000PM','DD-MON
---------------------------------------------------------------------------
15-SET-16 13:00:00,000000000
SQL>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.