Oracle Calling a job with arguments

 ̄綄美尐妖づ 提交于 2019-12-11 04:56:42

问题


I have a stored procedure parse_data which takes 3 arguments which are all NUMBER. I have created a program with three arguments and then a job that will run the stored procedure. The code looks like this:

BEGIN
  dbms_scheduler.create_program(program_name        => 'PARSE_PROGRAM',
                          program_type        => 'STORED_PROCEDURE',                                                          
                          program_action      => 'parse_data', 
                          number_of_arguments => 3,
                          enabled             => false,
                          comments            => '');

  dbms_scheduler.define_program_argument(program_name      => 'PARSE_PROGRAM',
                                   argument_name     => 'file_id',
                                   argument_position => 1,
                                   argument_type     => 'NUMBER',
                                   default_value     => '');

  dbms_scheduler.define_program_argument(program_name      => 'PARSE_PROGRAM',
                                   argument_name     => 'file_upload_id',
                                   argument_position => 2,
                                   argument_type     => 'NUMBER',
                                   default_value     => '');    

  dbms_scheduler.define_program_argument(program_name      => 'PARSE_PROGRAM',
                                   argument_name     => 'type_id',
                                   argument_position => 3,
                                   argument_type     => 'NUMBER',
                                   default_value     => '');                                       

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

  dbms_scheduler.create_job(job_name        => 'parse_job',
                          program_name    => 'PARSE_PROGRAM',
                          start_date      => systimestamp);

 END;

My question is now that this sql has been run and the program and job are now in the dbms, how do I actually make the call to run the job and pass in the 3 arguments?


回答1:


You should first create the job, then define the arguments, and then run it. When you create it, set the enabled atribute to false, so it won't run yet:

dbms_scheduler.create_job(job_name        => 'parse_job',
                          program_name    => 'PARSE_PROGRAM',
                          start_date      => systimestamp,
                          enabled         => false );

Then pass the arguments to the job:

dbms_scheduler.set_job_argument_value(job_name => 'parse_job',
                                      argument_position => 1,
                                      argument_value => 1);

Then enable it with a call:

dbms_scheduler.enable('parse_job');



回答2:


begin
 sys.dbms_scheduler.create_job(job_name            => 'Your Job name',
                        job_type            => 'PLSQL_BLOCK',
                        job_action          => 'begin schema.packagename.procedurename(parametername=> parametervalue); end;',
                        start_date          => to_date('01-01-2015 00:00:00', 'dd-mm-yyyy hh24:mi:ss'),
                        repeat_interval     => 'Freq=Monthly;Interval=1',
                        end_date            => to_date(null),
                        job_class           => 'DEFAULT_JOB_CLASS',
                        enabled             => false,
                        auto_drop           => true,
                        comments            => 'Job comment');
end;


来源:https://stackoverflow.com/questions/17948960/oracle-calling-a-job-with-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!