0

我有几千行查询可以正常工作很长时间,并且在某个时候开始返回:

ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 -  "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
           incorrect.  The input data did not contain a number where a number was
           required by the format model.
*Action:   Fix the input data or the date format model to make sure the
           elements match in number and type.  Then retry the operation.

我 99% 确定它是错误插入的日期。

我的问题是,如果日期格式不正确,是否有一个函数会返回日期或 NULL?

4

1 回答 1

4

To_date从 12.2 版开始就可以为您做到这一点。请参阅文档https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/TO_DATE.html

select to_date('not a date' default null on conversion error,'yyyymmdd') 
from dual;
于 2020-11-16T08:36:30.913 回答