0

我正在用确定的repeat_interval 做一份工作。我的目标是从表中检索该值,以便之后可以在表中更改该值并相应地修改作业。为此,我做了以下触发器:

CREATE OR REPLACE TRIGGER config_table_aur AFTER
  UPDATE OF value ON config_table FOR EACH row WHEN (new.property = 'job_interval') DECLARE v_job NUMBER;
  BEGIN
    dbms_job.submit (v_job, 'begin         
update_interval (' || :new.value || ');       
end;');
  END;

此触发器调用以下过程:

CREATE OR REPLACE
PROCEDURE update_interval(
    p_new_interval IN config_table.value%type)
AS
BEGIN
  dbms_scheduler.set_attribute ('jobu', 'repeat_interval', p_new_interval);
END update_interval;

其中 p_new_interval 是我从表中检索的值。我遇到的问题是,如果我尝试在表中设置一个值,如下所示:

FREQ=DAILY; INTERVAL=1;

然后我收到一条错误消息:

Fila 1: ORA-06550: line 2, column 46:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

   year month day hour minute second
The symbol ";" was ignored.
ORA-06512: at "SYS.DBMS_JOB", line 82
ORA-06512: at "SYS.DBMS_JOB", line 140
ORA-06512: at "SOMESCHEMA.CONFIG_TABLE_AUR", line 3
ORA-04088: error during execution of trigger 'SOMESCHEMA.CONFIG_TABLE_AUR'

我猜问题是属性值包含分号';' 因为如果我不使用它们,我不会得到错误。

你有什么建议来规避这个问题吗?

谢谢

4

1 回答 1

0

我猜问题是属性值包含分号';' 因为如果我不使用它们,我不会得到错误。

你有什么建议来规避这个问题吗?

呃......你的问题没有意义。您知道问题所在,但不想修复repeat_interval 日历语法中的语法错误?

对于这个简单的示例,您的触发器看起来不必要的复杂(但您可能有充分的理由使用DBMS_JOB)。这是一个示例,它首先将计划作业设置为在第 30 秒的每分钟运行一次,然后将repeat_intervalvia 配置表更改为每 10 秒运行一次:

--
-- scheduler configuration via tailored config table
--

create table scheduler_config (
  Job_name varchar2(100) not null,
  repeat_interval varchar2(100) not null
);

insert into scheduler_config values('logger1', 'FREQ=SECONDLY; BYSECOND=30');
commit;

create or replace trigger scheduler_config_trg
after update of repeat_interval
on scheduler_config
for each row
declare
  pragma autonomous_transaction;
begin
  -- Note: throws an exception if no such job
  dbms_scheduler.set_attribute(name => :new.job_name,
                               attribute => 'repeat_interval',
                               value => :new.repeat_interval);
end;
/
show errors

--
-- a simple job we want to schedule
--

create table scheduler_log (
  job_name varchar2(100),
  time timestamp(3),
  text varchar2(4000)
);

begin
  dbms_scheduler.create_job(
    job_name   => 'logger1',
    job_type   => 'PLSQL_BLOCK',
    job_action => 'BEGIN insert into scheduler_log values(''logger1'', systimestamp, ''Executed!''); commit; END;',
    start_date => systimestamp,
    repeat_interval => 'FREQ=SECONDLY; BYSECOND=30',
    end_date   => null,
    enabled    => true,
    comments   => 'Testing configuration');
end;
/

--
-- check how much work has been done and when
--

col job_name for a10
col time for a25
col text for a20

select * from scheduler_log order by time;

--
-- I want more job for my money !
--

update scheduler_config
   set repeat_interval = 'FREQ=SECONDLY; INTERVAL=10'
 where job_name = 'logger1';
commit;

--
-- remove the job
--

exec dbms_scheduler.drop_job('logger1')
于 2013-08-22T15:39:47.180 回答