我有一个从dbms作业调用的存储过程。即
DBMS_SCHEDULER.RUN_JOB ('Procedure_JB', FALSE);
一个java代码存储过程,在执行一些操作后,异步启动Procedure_JB。然后这个Procedure_JB调用Procedure_PRogram,然后程序将调用存储过程。
如何将参数传递给我的存储过程?
答案 0 :(得分:9)
定义您的作业Procedure_JB以接受参数。然后使用dbms_scheduler.set_job_argument_value定义要传递到作业将要运行的程序的参数的值。一个例子(取自https://forums.oracle.com/forums/thread.jspa?threadID=483135)
-- create a stored procedure with two arguments
create or replace procedure myproc (arg1 in varchar2, arg2 in varchar2)
is BEGIN null; END;
/
-- create a program with two arguments and define both
begin
dbms_scheduler.create_program
(
program_name=>'myprog',
program_action=>'myproc',
program_type=>'STORED_PROCEDURE',
number_of_arguments=>2, enabled=>FALSE
) ;
dbms_scheduler.DEFINE_PROGRAM_ARGUMENT(
program_name=>'myprog',
argument_position=>1,
argument_type=>'VARCHAR2',
DEFAULT_VALUE=>'13');
dbms_scheduler.DEFINE_PROGRAM_ARGUMENT(
program_name=>'myprog',
argument_position=>2,
argument_type=>'VARCHAR2');
dbms_scheduler.enable('myprog');
end;
/
-- create a job pointing to a program and set both argument values
begin
dbms_scheduler.create_job('myjob',program_name=>'myprog');
dbms_scheduler.set_job_argument_value('myjob',1,'first arg');
dbms_scheduler.set_job_argument_value('myjob',2,'second arg');
dbms_scheduler.enable('myjob');
end;
/
答案 1 :(得分:2)
改为使用PLSQL_BLOCK:
begin
dbms_scheduler.create_job (
job_name => 'myjob',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN myproc(''first arg'',''second arg''); END;',
start_date => sysdate,
repeat_interval => 'FREQ=HOURLY',
enabled => true
);
end;
/