您的位置:首页 > 数据库 > Oracle

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

2015-08-25 17:18 1241 查看
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 的函数格式后,问题解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle 函数