我有一个存储过程parse_data,它接受3个参数,这些参数都是NUMBER。我创建了一个包含三个参数的程序,然后是一个将运行存储过程的作业。代码如下所示:
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;
我现在的问题是这个sql已经运行了,程序和作业现在在dbms中,我如何实际调用运行作业并传入3个参数?
答案 0 :(得分:3)
您应首先创建作业,然后定义参数,然后运行它。创建它时,将启用的属性设置为false,因此它不会运行:
dbms_scheduler.create_job(job_name => 'parse_job',
program_name => 'PARSE_PROGRAM',
start_date => systimestamp,
enabled => false );
然后将参数传递给作业:
dbms_scheduler.set_job_argument_value(job_name => 'parse_job',
argument_position => 1,
argument_value => 1);
然后通过电话启用它:
dbms_scheduler.enable('parse_job');
答案 1 :(得分:0)
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;