oracle 试图在每 1 分钟后执行一项工作,但它不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2752870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:32:59  来源:igfitidea点击:

Trying to make a job to be executed after each 1 minute,but its not working?

oracleplsqloracle9idbms-job

提问by Vineet

I have made this job,that should be executed in an interval of 1 minute,but it's not working. When I use execute dbms_job.run(2);it gets executed. printeis a procedure Please suggest!

我做了这个工作,应该在 1 分钟的间隔内执行,但它不起作用。当我使用 execute dbms_job.run(2);它时会被执行。 printe是一个程序 请指教!

BEGIN
    DBMS_JOB.SUBMIT  (
         job =>:job_no,
             WHAT=>'printe;',--Procedure 
             next_date=>sysdate+1/24*60,
             interval=>'sysdate+1/24*60'
          );
    commit;
END;

采纳答案by Martin Milan

Try next_date = sysdate + (1/24/60) and interval = (1/24/60)...

尝试 next_date = sysdate + (1/24/60) 和 interval = (1/24/60) ...

回答by APC

Here is a simple job.

这是一个简单的工作。

SQL> create table log1 (ts timestamp)
  2  /

Table created.

SQL> create or replace procedure printe as
  2  begin
  3      insert into log1 values (systimestamp);
  4      commit;
  5  end;
  6  /

Procedure created.

SQL>

So the first thing is to submit it with both the start time and interval correctly specified. If you cannot remember how many minutes there are in a day (1440) it is a good idea to use brackets. Let's compare submitting the job with your date specifications ...

所以第一件事就是正确指定开始时间和间隔提交它。如果您不记得一天有多少分钟 (1440),最好使用括号。让我们将提交作业与您的日期规格进行比较......

SQL> var job_no number
SQL> BEGIN
   2     DBMS_JOB.SUBMIT
   3      (
   4      job =>:job_no,
   5      WHAT=>'printe;',--Procedure
   6      next_date=>sysdate+1/24*60,
   7    interval=>'sysdate+1/24*60'
   8    );
   9    commit;
  10  END;
  11  /

 PL/SQL procedure successfully completed.

 SQL> print job_no

     JOB_NO
 ----------
         71

 SQL>

... with brackets to assert precedence ...

... 用括号来声明优先级 ...

SQL> BEGIN
  2     DBMS_JOB.SUBMIT
  3      (
  4      job =>:job_no,
  5      WHAT=>'printe;',--Procedure
  6      next_date=>sysdate+1/(24*60),
  7    interval=>'sysdate+1/(24*60)'
  8    );
  9    commit;
 10  END;
 11  /

PL/SQL procedure successfully completed.

SQL> print job_no

    JOB_NO
----------
        72

SQL>

Clearly job 71 has not run and isn't going to run for some time yet:

显然,作业 71 还没有运行,也不会运行一段时间:

SQL>    select job, what, last_date, next_date, interval
  2  from user_jobs
  3  where job in (71,72)
  4  /

   JOB WHAT         LAST_DATE            NEXT_DATE            INTERVAL
------ ------------ -------------------- -------------------- -----------------
    71 printe;                           05-MAY-2010 17:35:34 sysdate+1/24*60
    72 printe;      03-MAY-2010 05:44:42 03-MAY-2010 05:45:34 sysdate+1/(24*60)

SQL>

Monitoring job 72 ....

监控作业 72 ....

SQL> select * from log1
  2  /

TS
-------------------------------------------------------------------
03-MAY-10 05:43:39.250000
03-MAY-10 05:44:42.296000

SQL>

So, if this still isn't working for you, what should you be doing? The first thing is to check whether the database is configured to run jobs at all. You will need DBA access for this.

那么,如果这仍然不适合您,您应该怎么做?第一件事是检查数据库是否配置为运行作业。为此,您将需要 DBA 访问权限。

SQL> select value
  2  from v$parameter
  3  where name='job_queue_processes'
  4  /

VALUE
-------------------------
1000

SQL>

If I remember correctly, in Oracle 9i the default value for this parameter is 0. It needs to be set to some non-zero value for jobs to run.

如果我没记错的话,在 Oracle 9i 中,此参数的默认值是 0。它需要设置为某个非零值才能运行作业。

And if that isn't the problem you need to check for error messages in the alert log. The background_dump_destdirectory may also have some .trc files produced by a failing job.

如果这不是问题,您需要检查警报日志中的错误消息。该background_dump_dest目录可能还有一些由失败的作业生成的 .trc 文件。