Oracle timed Task (Scheduler job) ____oracle

Source: Internet
Author: User

How to query the properties of a job from a database

SELECT * FROMUSER_SCHEDULER_JOBS;

or call the Get_attribute in the Dbms_scheduler package.

--============================================================

The use of--dbms_scheduler

--============================================================

--"SQL"

CreateTable Wty_test_scheduler

(

r_id VARCHAR2 (10),

R_date TIMESTAMP (6)

);

--Create Job

BEGIN

Dbms_scheduler.create_job (job_name=> ' job_create_wty_test ',

Job_type=> ' Plsql_block ',

Job_action=> ' BEGIN

INSERT into Wty_test_scheduler VALUES ("JOB", sysdate);

COMMIT;

End; ',

Enabled=>true,

Start_date=>systimestamp,

Repeat_interval=> ' Systimestamp + 1/1440 ',

Comments=> ' Job_create_wty_test '

);

End;

SELECT t.r_id,cast (t.r_date asdate) from Wty_test_schedulert;

Execdbms_scheduler.drop_job (' job_create_wty_test ');

SELECT * FROMUSER_SCHEDULER_JOBS;

--"Create job with Create_program"

Createorreplaceprocedure Sp_wty_test_scheduler

(in_id VARCHAR2)

Is

BEGIN

Insertinto Wty_test_scheduler VALUES (in_id,sysdate);

COMMIT;

End;

--Create Program

BEGIN

Dbms_scheduler.create_program (program_name=> ' Program_wty_test_scheduler ',

Program_action=> ' Sp_wty_test_scheduler ',

Program_type=> ' Stored_procedure ',

Number_of_arguments=>1,

Comments=> ' Wty_test_scheduler_program ',

Enabled => FALSE

);

End;

Execdbms_scheduler.drop_program (' Program_wty_test_scheduler ');

SELECT * FROMUSER_SCHEDULER_PROGRAMS;

--Set Progam parameters

BEGIN

Dbms_scheduler.define_program_argument (program_name=> ' Program_wty_test_scheduler ',

Argument_position=>1,

Argument_type=> ' Varchar2 ',

Default_value => ' program '

);

End;

--Execution Program (Command window)

Execdbms_scheduler.enable (' Program_wty_test_scheduler ');

SELECT t.r_id,cast (t.r_date asdate) from Wty_test_schedulert;

--dbms_sheduler Run Information

SELECT

T.job_name,

T.enabled,

Cast (T.last_start_date asdate),

T.schedule_name

From User_scheduler_jobs t

Wheret.job_name= ' job_create_wty_test ';

--dbms_scheduler running success or failure information

SELECT

T.job_name,

T.status,

CAST (t.actual_start_date asdate) start_date,

CAST (t.log_date asdate) log_date

From User_scheduler_job_run_details t

Wheret.job_name= ' Job_create_wty_test '

Andtrunc (CAST (t.log_date asdate)) =date ' 2016-11-16 '

Orderby4desc;

--Query execution time

SELECT

T1. Window_name,

T1. Repeat_interval,

T1.duration

From Dba_scheduler_windows T1,

Dba_scheduler_wingroup_memberst2

Wheret1.window_name=t2. Window_name

and T2. Window_group_name= ' Maintenance_window_group ';

--Modify Execution time

BEGIN

Dbms_scheduler.set_attribute (' Weekend_window ', ' reoeat_interval ', ' freq=daily;byday=sat;byhour=0;bysecond=0 ');

Dbms_scheduler.set_attribute (' Weekend_window ', ' DURATION ', ' +000 04:00:00 ');

End;

--turn JOB Job_rosanu into a running state

BEGIN

Dbms_scheduler.enable (' Program_wty_test_scheduler ');

End;

--Check job run time long

SELECT

T.job_name,

T.state,

T.enabled,

CAST (t.last_start_date asdate) Last run time,

CAST (t.next_run_date asdate) Next Run time

From User_scheduler_jobs t

WHERE t.job_name= ' Job_rosanu ';

Note: View scheduled task execution time according to Repeat_interval:

freq=daily; byhour=23; byminute=30; Bysecond=0

The execution time is 23:00:00 every day

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.