Oracle Calling a job with arguments

oracleoracle10goracle11gplsql

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?

Best Answer

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');