ora-01861:文字与格式字符串不匹配解决方案

前言

        按照对接文档,提供的时间字段是字符串,将字符串转换成时间戳返回:

SQL:select guid, puc_id, system_id, org_identifier, org_alias, org_code, enable_flag, update_time from typppbd.view_puc_organization where update_time is not null order by to_date(update_time, 'yyyy-MM-dd hh24:mi:ss') desc

执行出错,结果如上


问题原因

            实际上数据库的update_time字段是DATE类型的,所以上述的写法是错误的


正确的写法

select guid, puc_id, system_id, org_identifier, org_alias, org_code, enable_flag, to_char(update_time, 'yyyy-mm-dd hh24:mi:ss') from typppbd.view_puc_organization where update_time is not null order by update_time desc


这个时候,采用to_char将时间类型的数据转换成字符串,否则,通过OTL C++组件访问的时候,抛异常


总结

        编写SQL语句的时候,必须将现场数据库表的字段和数据导出来,进行检验,文档不一定靠谱,因为默认情况下,认为日期是标准格式:2020-10-10 10:10:10

猜你喜欢

转载自blog.51cto.com/fengyuzaitu/2537336