解释“ORA-01870:间隔或日期时间不可相互比较”

时间:2010-08-31 10:02:52

标签: oracle oracle11g jobs dbms-scheduler

在SQL Developer中针对Oracle 11g执行此代码时出现错误,

begin
dbms_scheduler.create_job(
  job_name => 'comuni_34',
  job_type => 'plsql_block',
  job_action => 'begin com_auth_api.expire_old_passwords; end;',
  start_date => to_date('2009-jan-01 01:15:00', 'yyyy-mon-dd hh24:mi:ss'),
  repeat_interval => 'freq=daily',
  enabled => true,
  comments => 'Expire old passwords'
);
end;

这是错误,

Error starting at line 4 in command:
begin
dbms_scheduler.create_job(
  job_name => 'comuni_34',
  job_type => 'plsql_block',
  job_action => 'begin com_auth_api.expire_old_passwords; end;',
  start_date => to_date('2009-jan-01 01:15:00', 'yyyy-mon-dd hh24:mi:ss'),
  repeat_interval => 'freq=daily',
  enabled => true,
  comments => 'Expire old passwords'
);
end;
Error report:
ORA-01870: the intervals or datetimes are not mutually comparable
ORA-06512: at "SYS.DBMS_ISCHED", line 99
ORA-06512: at "SYS.DBMS_SCHEDULER", line 268
ORA-06512: at line 2
01870. 00000 -  "the intervals or datetimes are not mutually comparable"
*Cause:    The intervals or datetimes are not mutually comparable.
*Action:   Specify a pair of intervals or datetimes that are mutually
           comparable.

谷歌搜索没有帮助,因为它刚刚列出了大量无用的Oracle错误代码网站。

也许SYS.DBMS_ISCHED / SYS.DBMS_SCHEDULER的来源可以解释这一点。

更新:使用'2010-apr-20 01:15:00'而不是'2009-jan-01 01:15:00'的另一项工作可能问题就是问题是日期太远了过去没有正确处理。

更新:使用'2009-apr-01 01:15:00'代替'2009-jan-01 01:15:00'刚刚奏效。然而'2009-mar-01 01:15:00'没有用,所以限制一个工作可以开始多远。由于我已经解决了我的问题,我不能接受一个重复我的解决方案的答案,但如果有人想进一步解释,我会考虑接受这个。

4 个答案:

答案 0 :(得分:1)

我没有11g测试它,但是在10.2.0.4数据库上,CREATE_JOB早在01-JAN-1970就在START_DATE成功了。这可能是一个错误,如果您有权访问,您可能需要检查Metalink。

答案 1 :(得分:1)

我认为你的会话中有一组错误的NLS_LANG *参数。 SQL Developer自动完成。在sqlplus的脚本的beginnig中尝试这个地方:

ALTER SESSION SET NLS_LANGUAGE= 'AMERICAN';
ALTER SESSION SET NLS_TERRITORY= 'AMERICA';

之后尝试运行:

begin
dbms_scheduler.create_job(
  job_name => 'comuni_34',
  job_type => 'plsql_block',
  job_action => 'begin com_auth_api.expire_old_passwords; end;',
  start_date => to_date('2009-jan-01 01:15:00', 'yyyy-mon-dd hh24:mi:ss'),
  repeat_interval => 'freq=daily',
  enabled => true,
  comments => 'Expire old passwords'
);
end;
/

答案 2 :(得分:1)

谢谢!这是我发现的有关该问题的唯一相关信息,Google未显示任何结果...

我在使用SQL Developer 18.3.0.277和Oracle 12c数据库时遇到了类似的问题。

它过去几次对我有用,但是突然它显示出ora-01870错误。

我尝试过

ALTER SESSION SET NLS_LANGUAGE= 'AMERICAN';
ALTER SESSION SET NLS_TERRITORY= 'AMERICA';

但这没有帮助。

最后,真正的帮助是SQL Developer重新启动。断开连接并连接或删除作业/创建作业无济于事。每当我要启用该作业时,都会显示该错误。

在发生问题之前,我没有进行任何更改会话或类似操作。我只是禁用了作业,当我想再次启用该错误时,就会显示该错误。

答案 3 :(得分:0)

您可能会考虑函数OVERLAPS的行为。我不知道Scheduler是否使用它,但错误信息是相同的:

SQL> select 1 from dual where (sysdate,sysdate+2) overlaps (sysdate+1,sysdate+5);

         1
----------
         1

SQL> select 1 from dual where (null,sysdate+2) overlaps (sysdate+1,sysdate+5);
         1
----------
         1

SQL> select 1 from dual where (sysdate+2,null) overlaps (sysdate+1,sysdate+5);
         1
----------
         1

SQL> select 1 from dual where (null,null) overlaps (sysdate+1,sysdate+5);
select 1 from dual where (null,null) overlaps (sysdate+1,sysdate+5)

ORA-01870: the intervals or datetimes are not mutually comparable