ORA-30081: 下面提到的查询的 datetime/interval 算法的数据类型无效

ORA-30081: invalid data type for datetime/interval arithmetic for the below mentioned query

select LASTCHANGEDATE 
from ROH_TRANSFER 
where LASTCHANGEDATE BETWEEN to_char(sysdate,'yyyy/mm/dd') - INTERVAL '10' DAY AND to_char(sysdate,'yyyy/mm/dd');

对于上述查询,我​​收到以下错误:

where LASTCHANGEDATE BETWEEN to_char(sysdate,'yyyy/mm/dd') - INTERVAL '10' DAY AND to_char(sysdate,'yyyy/mm/dd')
                             *
ERROR at line 1:
ORA-30081: invalid data type for datetime/interval arithmetic

请帮我解决这个问题..!

注意:这是我的 LASTCHANGEDATE 列内容的样子:

LASTCHANGEDATE
--------------------------------
2016/11/09 02:10:01.066
2016/11/09 18:08:09.319

在执行算术运算或比较之前不需要将 DATE 转换为 CHAR/VARCHAR

所以尝试:

select LASTCHANGEDATE 
  from ROH_TRANSFER 
 where LASTCHANGEDATE between sysdate - INTERVAL '10' DAY AND sysdate;

或者如果您想截断当前日期

select LASTCHANGEDATE 
  from ROH_TRANSFER 
 where LASTCHANGEDATE between trunc(sysdate, 'DDD') - INTERVAL '10' DAY AND trunc(sysdate, 'DDD');

可能您想这样做:

select LASTCHANGEDATE from ROH_TRANSFER where LASTCHANGEDATE BETWEEN to_char(sysdate - INTERVAL '10' DAY,'yyyy/mm/dd') AND to_char(sysdate,'yyyy/mm/dd')