我认为space(<field>, ,<field>)
您的数据中有导致问题的原因。
最好TRIM
在使用它们之前使用。
以下是一些使用不同值进行演示的示例:
-- working fine with correct timestamp values
SQL> SELECT
2 CAST(TO_TIMESTAMP('2019-11-05 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF3') AS DATE) as dt
3 FROM
4 DUAL;
DT
---------
05-NOV-19
-- working fine with a null value
SQL>
SQL> SELECT
2 CAST(TO_TIMESTAMP(NULL, 'YYYY-MM-DD HH24:MI:SS.FF3') AS DATE) as dt
3 FROM
4 DUAL;
DT
---------
-- working fine with an empty value
SQL>
SQL> SELECT
2 CAST(TO_TIMESTAMP('', 'YYYY-MM-DD HH24:MI:SS.FF3') AS DATE) as dt
3 FROM
4 DUAL;
DT
---------
现在显示错误和解决方案
-- giving an error with space in the value -- Your case
-- might be you are considering it as the null
-- but it is actually a value that is a space character
SQL>
SQL> SELECT
2 CAST(TO_TIMESTAMP(' ', 'YYYY-MM-DD HH24:MI:SS.FF3') AS DATE) as dt
3 FROM
4 DUAL;
CAST(TO_TIMESTAMP(' ', 'YYYY-MM-DD HH24:MI:SS.FF3') AS DATE) as dt
*
ERROR at line 2:
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
-- Solution to your issue -- using TRIM
SQL>
SQL> SELECT
2 CAST(TO_TIMESTAMP(TRIM(' '), 'YYYY-MM-DD HH24:MI:SS.FF3') AS DATE) as dt
3 FROM
4 DUAL;
DT
---------
SQL>
干杯!!