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 的函数格式后,问题解决。
上网查资料得到如下:
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 的函数格式后,问题解决。
相关文章推荐
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- Oracle Containers for J2EE远程安全漏洞(CVE-2014-0413)
- Oracle 10g R2不能使用EM的问题
- 表空间操作
- PreparedStatement中in子句的处理
- VMware下RedHat4.8_64位安装Oracle 10g RAC--简略脚本
- oracle sql日期比较
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- OS block size和Oracle block size,查找OS Blocksize的方法
- oracle中创建数据库和表空间的几点总结
- 数据库自动备份脚本
- Mootools 1.2教程 函数
- autoit InputBox 函数
- 文件遍历排序函数
- oracle的nvl函数的使用介绍
- 解决oracle用户连接失败的解决方法
- oracle的一些tips技巧
- Oracle 下的开发日积月累
- Oracle存储过程之数据库中获取数据实例