核心问题是,在会话级别,您nls_numeric_characters=',.'
的时间戳字符串包含点 ( .
) 作为 seconds-from-microseconds 分隔符。
该to_timestamp()
函数可以接受用于覆盖 NLS 设置的第三个参数。这是给你的一个小演示......
Connected to Oracle Database 12c Enterprise Edition Release 12.1.0.2.0
Connected as ******@******
--- This is how it behaves in your database (with "," as the decimals separator) ...
SQL> alter session set nls_numeric_characters = ',.';
Session altered
SQL> select to_timestamp('21-OCT-15 08.24.30.000000000 PM','DD-MON-RR HH.MI.SSXFF AM') as xx from dual;
select to_timestamp('21-OCT-15 08.24.30.000000000 PM','DD-MON-RR HH.MI.SSXFF AM') as xx from dual
ORA-01855: AM/A.M. or PM/P.M. required
--- This is how it behaves in my database (with "." as the decimals separator) ...
SQL> alter session set nls_numeric_characters = '. ';
Session altered
SQL> select to_timestamp('21-OCT-15 08.24.30.000000000 PM','DD-MON-RR HH.MI.SSXFF AM') as xx from dual;
XX
-------------------------------------------------
21.10.15 20:24:30.000000000
--- Now back to your database settings and let's make the conversion NLS-settings-indepenent ...
SQL> alter session set nls_numeric_characters = ',.';
Session altered
SQL> select to_timestamp('21-OCT-15 08.24.30.000000000 PM','DD-MON-RR HH.MI.SSXFF AM', 'nls_numeric_characters = ''. ''') as xx from dual;
XX
-------------------------------------------------
21.10.15 20:24:30,000000000
SQL>
请注意第三to_timestamp()
个 SELECT 中函数的第三个参数。除了所有其他正确答案之外,您也可以这样做。