oracle ora 01850,Oracle SQL to_date & to_timestamp ORA-01858: a non-numeric character was found wher...

该博客讲述了在Oracle SQL中遇到日期转换错误(ORAs-01858和01850)的解决方案,作者建议将to_date替换为to_char,并提供了一个实例,说明如何使用to_char处理TIMESTAMP类型,确保日期格式正确。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

I have a small bit of code:

Code

SELECT to_date(it.DSTAMP, 'DD/MM/YYYY') AS "Date", to_timestamp(it.DSTAMP, 'HH24:MI:SS') AS Time

FROM itable it

Errors

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.

Error if I remove to_date

ORA-01850: hour must be between 0 and 23

01850. 00000 - "hour must be between 0 and 23"

*Cause:

*Action:

The DSTAMP field returns 24-SEP-14 08.55.33.997545000 without any formatting.

Obviously expected output is

24/09/2014 & 08:55:34

回答1:

It seems that it.DSTAMP is a TIMESTAMP

Replace to_date and to_timestamp with to_char

SELECT to_char(it.DSTAMP, 'DD/MM/YYYY') AS "Date", to_char(it.DSTAMP, 'HH24:MI:SS') AS Time

FROM itable it

来源:https://stackoverflow.com/questions/27425515/oracle-sql-to-date-to-timestamp-ora-01858-a-non-numeric-character-was-found-w

异常"ORA-01858: a non-numeric character was found where a numeric was expected"表示在期望为数字的地方发现了一个非数字字符。这个错误通常在数据类型转换或日期格式问题中出现。根据引用的信息,这个错误可能与日期字段的默认日期转换有关。 为了确定出错的日期值,可以执行以下操作: 1. 使用以下查询语句查找出错的行和对应的日期值: select rowid, to_char(y,'dd-MON-yy') from tbsg.TB_CNB_TEMPPAYRECORD; 根据引用的信息,可以看到有一个日期值为"00-000-00"的行,这是错误的日期格式,因此导致了异常。 解决这个问题的方法是修改错误的日期值或更正日期的格式,确保它符合正确的日期格式。一旦修改后,再次执行查询操作应该就不会再出现这个异常了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ORA-01858: a non-numeric character was found where a numeric was expected 的一种可能错误情况](https://blog.csdn.net/libertine1993/article/details/109084464)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [ORA-01858: a non-numeric character was found where a numeric was expected](https://blog.csdn.net/congshanlan2358/article/details/100487536)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Oracle sqldeveloper without jdk (win+linux)](https://download.csdn.net/download/vicle/766540)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值