oracle create a scheduled task

. 1--1 Create Test Table 
 2 Table job_test Create (ID Integer, ADD_TIME DATE); 
 . 3 
 . Create a stored procedure. 4 --2 
 . 5 Create or Replace Procedure prc_job_test IS   
 . 6 the begin   
 . 7 INSERT INTO job_test values (SEQ_TM_ID.nextval, SYSDATE) ;   
 . 8 the commit;   
 . 9 End prc_job_test; 
10 
. 11 --3 create a task. 
12 is DECLARE   
13 is tm_job Number;   
14 the begin   
15 sys.dbms_job.submit (tm_job, - the task name   
16 'prc_job_test;', - during the execution of   
17 sysdate , - execution time   
18 'sysdate + 1 / (24 * 60 * 10)'); - the next execution time   
. 19 End; 
20 is 
. 21 is --4 query task 
22 is SELECT * from DBA_JOBS; 
23 is
. 24 SELECT * T, T t.rowid from job_test Order by ADD_TIME desc 
25 
26 is --5 tasks. 
27 the begin   
28 dbms_job.run (25); - 25 for the task ID   
29 End;    
30 
31 is --6. stop task 
32 the begin 
33 is dbms_job.broken (25, to true, SYSDATE); 
34 is the commit; 
35 End; 
36 
. 37 [7 ì delete task 
38 is the begin   
39 DBMS_JOB.REMOVE (25);   
40 End;   
Copy the code
1 --8.删除任务脚本
2 begin
3   for v in(select job from dba_jobs where what = 'prc_job_test;') loop
4     dbms_job.remove(v.job);
5   end loop;
6   commit;
7 end;
Copy the code

 



Copy the code

 

Complete script example:

 

Copy the code
. 1--1 Delete Script Table 
 2 NUMBER NUM the DECLARE; 
 . 3 the BEGIN 
 . 4 the SELECT 
 . 5 COUNT (. 1) the INTO NUM 
 . 6 the FROM 
 . 7 USER_TABLES 
 . 8 the WHERE 
 . 9 TABLE_NAME = 'JOB_TEST'; 
10. 1 THEN the IF NUM = 
. 11 the EXECUTE IMMEDIATE ' 
12 is drop Table jOB_TEST 
13 is'; 
14 the END the IF; 
15 the END; 
16 / 
.. 17 --2 Create test table 
18 is Create table job_test (ID Integer, ADD_TIME DATE); 
. 19 / 
. 20 is to create a stored procedure --3 
21 create or replace procedure PRC_JOB_TEST is   
the begin 22   
23 INSERT INTO job_test values (1, sysdate);   
24-the commit;   
25 End prc_job_test; 
26 is /
27--4 delete job script. 
28 the begin 
29 for V in (SELECT Job from DBA_JOBS WHERE What = 'PRC_JOB_TEST;') Loop 
30 DBMS_JOB.REMOVE (v.job); 
31 is End Loop; 
32 the commit; 
33 is End; 
34 is / 
. 35--5 create a task 
36 DECLARE   
37 [tm_job Number;   
38 is the begin   
39 sys.dbms_job.submit (tm_job, - the task name   
40 'PRC_JOB_TEST;', - process performed   
41 sysdate, - execution time   
42 'sysdate + 1 / (24 * 60 * 10) '); - the next execution time   
43 is a COMMIT; 
44 is End; 

original link: https: //www.cnblogs.com/zyx-/p/8032954.html

Guess you like

Origin www.cnblogs.com/irishua/p/11263049.html