2

Im not clear about this, here in DBMS_SCHEDULER we have CREATE_PROGRAM CREATE_JOB CREATE_SCHEDULE etc., after reading the oracle doc still im unclear what to use, On the Oracle side, i am going to use DBMS_SCHEDULER to insert a new message into the queue at the appropriate time, i planned to create scheduler to execute it on particular time and then create program to execute my PL/SQL block which will enqueue the message in the queue Or instead of using CREATE_SCHEDULE and CREATE_PROGRAM, CREATE_JOB does both the jobs, which to use? please guide me whether i am doing correctly, if not please correct me.

Thankyou

4

1 回答 1

4

create_job是安排通话的基本通话。您不必创建命名程序或时间表来执行此操作。如果您有多个要使用此调用的作业,则创建命名程序/时间表很有用。您可以只引用指定的程序时间表,而不是让每个作业都保存一份副本。

例如,如果您有 5 个作业想要调用您的包MYPKG.ENTRY_PROG(param) ,并且每个作业只使用不同的参数值,我会说您想使用create_program来定义该 pl/sql 调用,然后create_job引用该程序名称 + 设置选择的参数值. 这样,如果您想稍后重命名 API 或其他什么,您不必更改五个单独的作业来执行此操作。

如果您的工作只是一个独立的工作,它调用不会被其他工作调用的例程,那么您不必使用create_program/ create_schedule,直接使用create_job即可。

我使用的一个示例create_program是调用测试工具。我的测试工具包被调用pkg_test_harness.queue_tests(p_set_name in varchar2),因此我定义了一些作业,这些作业将各种 API 排入队列,以便在上午 9 点、中午 12 点和下午 5 点运行。我没有单独定义每个作业调用,而是create_program像这样调用:

    dbms_output.put('Setting up TEST_HARNESS_ENQUEUE scheduler program...');
    dbms_scheduler.create_program(program_name        => 'TEST_HARNESS_ENQUEUE',
                                  program_type        => 'STORED_PROCEDURE',                                                          
                                  program_action      => 'pkg_test_harness.queue_tests', 
                                  number_of_arguments => 1,
                                  enabled             => false,
                                  comments            => 'Program to enqueue a set of API test for the test harness to run.');

    dbms_scheduler.define_program_argument(program_name      => 'TEST_HARNESS_ENQUEUE',
                                           argument_name     => 'p_set_name',
                                           argument_position => 1,
                                           argument_type     => 'VARCHAR2',
                                           default_value     => '');

    dbms_scheduler.enable (name => 'TEST_HARNESS_ENQUEUE');

    dbms_output.put_line('done.');

然后每个“工作”都被定义为指向程序。

dbms_output.put('Setting up TEST_HARNESS_ENQUEUE_9AM scheduler job...');
dbms_scheduler.create_job(job_name        => 'TEST_HARNESS_ENQUEUE_9AM',
                          program_name    => 'TEST_HARNESS_ENQUEUE',
                          start_date      => systimestamp,
                          end_date        => null,
                          repeat_interval => 'freq=daily; byhour=9; byminute=0; bysecond=0;',
                          enabled         => true,
                          auto_drop       => false,
                          comments        => 'Job to enqueue a set of API test for the test harness to run.');

dbms_scheduler.set_job_argument_value(job_name          => 'TEST_HARNESS_ENQUEUE_9AM',
                                      argument_position => 1,
                                      argument_value    => 'DAILY_9AM');
dbms_output.put_line('done.');

dbms_output.put('Setting up TEST_HARNESS_ENQUEUE_12PM scheduler job...');
dbms_scheduler.create_job(job_name        => 'TEST_HARNESS_ENQUEUE_12PM',
                          program_name    => 'TEST_HARNESS_ENQUEUE',
                          start_date      => systimestamp,
                          end_date        => null,
                          repeat_interval => 'freq=daily; byhour=12; byminute=0; bysecond=0;',
                          enabled         => true,
                          auto_drop       => false,
                          comments        => 'Job to enqueue a set of API test for the test harness to run.');

我没有创建一个命名的时间表,因为这些时间表是个别工作所独有的。

于 2012-12-24T10:46:59.597 回答