Unless you have a trigger on the table that is setting a date or timestamp column, which would give some indication in the full error stack, it sounds like your NLS_DATE_LANGUAGE
is not expecting an English-language month abbreviation.
What you have is valid in English:
alter session set nls_timestamp_format = 'RR/MM/DD HH24:MI:SSXFF';
alter session set nls_date_language ='ENGLISH';
select to_timestamp('15-APR-14 01.36.58.803000000 PM',
'DD-MON-RR HH.MI.SS.FF AM') as my_date
from dual;
MY_DATE
---------------------------
14/04/15 13:36:58.803000000
But if your session's default date language is Polish (guessing from your profile) it will give this error - with the error message still in English:
alter session set nls_date_language ='POLISH';
select to_timestamp('15-APR-14 01.36.58.803000000 PM',
'DD-MON-RR HH.MI.SS.FF AM') as my_date
from dual;
SQL Error: ORA-01843: not a valid month
01843. 00000 - "not a valid month"
If you don't want to set your session to English you can override that for a specific statement by giving the optional third parameter to to_timestamp()
:
alter session set nls_date_language ='POLISH';
select to_timestamp('15-APR-14 01.36.58.803000000 PM',
'DD-MON-RR HH.MI.SS.FF AM',
'NLS_DATE_LANGUAGE=ENGLISH') as my_date
from dual;
MY_DATE
---------------------------
14/04/15 13:36:58.803000000
You can also avoid the issue entirely by using month numbers instead of month names, or using the ANSI timestamp literal syntax:
select timestamp '2014-04-15 13:36:58.803' from dual;
TIMESTAMP'2014-04-1513:36:58.803'
---------------------------------
14/04/15 13:36:58.803000000
These methods also all work for date columns; the to_date()
function is affected by NLS settings in the same way and has the same optional date language parameter.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…