oracle日期时间段查询遇到问题to_date ora-01847 day of month must be between 1 and last day of month

oracle日期时间段查询时遇到问题:to_date ora-01847 day of month must be between 1 and last day of month

上网查资料得到如下:

select to_timestamp(to_char(start_date1,'DD-MON-YYYY')||' '||NVL(start_time1,'00:00'),'DD-MON-YYYY HH24:MI') from table1

资料有如下描述:

The NVL() description says:

    The arguments expr1 and expr2 can have any data type. If their data types are different, then Oracle Database implicitly converts one to the other. If they cannot be converted implicitly, then the database returns an error. The implicit conversion is implemented as follows:

    If expr1 is character data, then Oracle Database converts expr2 to the data type of expr1 before comparing them and returns VARCHAR2 in the character set of expr1.

    If expr1 is numeric, then Oracle Database determines which argument has the highest numeric precedence, implicitly converts the other argument to that data type, and returns that data type.

意思是,在同一个SQL语句中,时间参数的类型(格式)要一致。如果不一致,oracle就会把一个类型转换成另一种类型,若转换失败就会抛出异常。所以当出现该问题时,一定要检查整句SQL语句中的日期时间格式,问题便会迎刃而解。


修改格式化函数to_date 的函数格式后,问题解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值