|
1. 普通的基于时间的作业:
- BEGIN
- DBMS_SCHEDULER.CREATE_PROGRAM(
- program_name=>'"HR"."PROGRAM1"',
- program_action=>'begin
- update employees set salary=salary+1 where employee_id=100;
- commit;
- end;',
- program_type=>'PLSQL_BLOCK',
- number_of_arguments=>0,
- comments=>'program1',
- enabled=>TRUE);
- END;
复制代码- BEGIN
- sys.dbms_scheduler.create_schedule(
- repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
- start_date => to_timestamp_tz('2018-08-09 21:25:00 Asia/Shanghai', 'YYYY-MM-DD HH24:MI:SS TZR'),
- end_date => to_timestamp_tz('2018-08-09 21:28:00 Asia/Shanghai', 'YYYY-MM-DD HH24:MI:SS TZR'),
- comments => 'schedule1',
- schedule_name => '"HR"."SCHEDULE1"');
- END;
复制代码- BEGIN
- sys.dbms_scheduler.create_job(
- job_name => '"HR"."JOB1"',
- program_name => '"HR"."PROGRAM1"',
- schedule_name => '"HR"."SCHEDULE1"',
- job_class => '"DEFAULT_JOB_CLASS"',
- comments => 'job1',
- auto_drop => FALSE,
- enabled => TRUE);
- END;
复制代码 | Operation Detail | |
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
| |
| |
| |
| |
| |
| |
| |
| | [table] |
| |
| |
| |
| |
| |
| |
| |
| | | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
Select | Log ID | Log Date | Operation | Status |
| |
| |
| |
| |
| |
| |
| |
| | 389 | Aug 9, 2018 9:27:30 PM +08:00 | COMPLETED |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | 388 | Aug 9, 2018 9:27:30 PM +08:00 | RUN | SUCCEEDED |
| |
| |
| |
| |
| |
| |
| |
| | 387 | Aug 9, 2018 9:27:00 PM +08:00 | RUN | SUCCEEDED |
| |
| |
| |
| |
| |
| |
| |
| | 386 | Aug 9, 2018 9:26:30 PM +08:00 | RUN | SUCCEEDED |
| |
| |
| |
| |
| |
| |
| |
| | 385 | Aug 9, 2018 9:26:00 PM +08:00 | RUN | SUCCEEDED |
| |
| |
| |
| |
| |
| |
| |
| | 384 | Aug 9, 2018 9:25:30 PM +08:00 | RUN | SUCCEEDED |
| |
| |
| |
| |
| |
| |
| |
| | 383 | Aug 9, 2018 9:25:00 PM +08:00 | RUN | SUCCEEDED |
|
2. 外部的基于时间的作业:
/home/oracle/job2.sh
- #!/bin/sh
- date +%Y%m%d-%H%M%S >> /home/oracle/job2.log
复制代码- grant create external job to hr;
复制代码- select * from dba_scheduler_credentials;
复制代码 默认为空。
- begin
- dbms_scheduler.create_credential(credential_name => 'credential1',
- username => 'oracle',
- password => 'oracle');
- end;
复制代码- select * from dba_scheduler_credentials;
复制代码 | OWNER | CREDENTIAL_NAME | USERNAME | DATABASE_ROLE | WINDOWS_DOMAIN | COMMENTS | 1 | SYS | CREDENTIAL1 | oracle | | | |
- grant execute on credential1 to hr;
复制代码- BEGIN
- DBMS_SCHEDULER.CREATE_PROGRAM(
- program_name=>'"HR"."PROGRAM2"',
- program_action=>'/home/oracle/job2.sh',
- program_type=>'EXECUTABLE',
- number_of_arguments=>0,
- comments=>'PROGRAM2',
- enabled=>TRUE);
- END;
复制代码- BEGIN
- sys.dbms_scheduler.create_schedule(
- repeat_interval => 'FREQ=SECONDLY;INTERVAL=30',
- start_date => to_timestamp_tz('2018-08-09 21:44:00 Asia/Shanghai', 'YYYY-MM-DD HH24:MI:SS TZR'),
- end_date => to_timestamp_tz('2018-08-09 21:46:00 Asia/Shanghai', 'YYYY-MM-DD HH24:MI:SS TZR'),
- comments => 'schedule2',
- schedule_name => '"HR"."SCHEDULE2"');
- END;
复制代码- BEGIN
- sys.dbms_scheduler.create_job(
- job_name => '"HR"."JOB2"',
- program_name => '"HR"."PROGRAM2"',
- schedule_name => '"HR"."SCHEDULE2"',
- job_class => '"DEFAULT_JOB_CLASS"',
- comments => 'job2',
- auto_drop => FALSE,
- enabled => FALSE);
- DBMS_SCHEDULER.SET_ATTRIBUTE(name => '"HR"."JOB2"', attribute => 'credential_name', value => '"SYS"."CREDENTIAL1"' );
- sys.dbms_scheduler.enable( '"HR"."JOB2"' );
- END;
复制代码 | Operation Detail | |
| | | [table=98%]
| | [table]
| | | |
|
| |
|
Select | Log ID | Log Date | Operation | Status | | 394 | Aug 9, 2018 9:45:30 PM +08:00 | COMPLETED |
| | | 393 | Aug 9, 2018 9:45:30 PM +08:00 | RUN | SUCCEEDED | | 392 | Aug 9, 2018 9:45:00 PM +08:00 | RUN | SUCCEEDED | | 391 | Aug 9, 2018 9:44:30 PM +08:00 | RUN | SUCCEEDED | | 390 | Aug 9, 2018 9:44:00 PM +08:00 | RUN | SUCCEEDED |
| [/td][/tr]
[/table]
|
|