您的位置:首页 > 数据库 > Oracle

动态修改oracle job 让job在指定时间执行

2012-03-17 12:04 375 查看
动态修改oracle job 让job在指定时间执行

PROCEDURE Wsp_Call_MillAcident (

an_acidentId IN VARCHAR2,--发生事故的ID值为字符串类型

at_acidentime IN VARCHAR2,--发生事故的时间精确到秒(YYYY-MM-DD HH24:MI:SS)

an_preSeconds IN NUMBER,--发生事故前n秒为复数

an_aftSeconds IN NUMBER--发生事故后n秒

)

AS

strSql varchar2(2000);

startTime varchar2(30);

endTime varchar2(30);

calltime varchar2(30);

acidenttime date;

ln_preSeconds NUMBER;

ln_aftSeconds NUMBER;

BEGIN

if (an_acidentId is null) then

RETURN;

end if;

if (at_acidentime is null) then

acidenttime:=sysdate;

else

acidenttime:=to_date(at_acidentime,'YYYY-MM-DD HH24:MI:SS');

end if;

if ( an_preSeconds is null ) then

ln_preSeconds :=ACIDENT_PRE_SECONDS;

else

ln_preSeconds:=an_preSeconds;

end if;

if ( an_aftSeconds is null ) then

ln_aftSeconds :=ACIDENT_AFT_SECONDS;

else

ln_aftSeconds :=an_aftSeconds;

end if;

--计算事故发生时间at_acidentime之前an_preSeconds秒的时间

startTime :=fc_getnextsecondstime(acidenttime,ln_preSeconds); --样式'yyyy-mm-dd hh24:mi:ss'

--计算事故发生时间at_acidentime之后an_aftSecends秒的时间

endTime :=fc_getnextsecondstime(acidenttime,ln_aftSeconds); --样式'yyyy-mm-dd hh24:mi:ss'

--计算作业调用时间与endtime相同

calltime :=endTime || ' +8:00'; --样式'2008-07-10 10:01:00 +8:00'

--构造作业执行程序,将各遥测表中按以上两个计算出来的时间取值,注入到事故追忆历史表

strSql :='begin

insert into ACIDNT_RETROS_HIS( ID, POINT_ID, POINT_IDENTIFIER, POINT_VALUE, GET_TIME, POINT_TYPE, ACCIDENT_ID)

select t1.ID || systimestamp, t1.POINT_ID, t1.POINT_IDENTIFIER,t1.POINT_VALUE,t1.GET_TIME,t1.POINT_TYPE, '|| an_acidentId ||' from ACIDNT_RETROS_TEMP t1;

commit;

end;';

--dbms_output.put_line(startTime);

--dbms_output.put_line(endTime);

dbms_output.put_line(calltime);

dbms_output.put_line(strSql);

--修改作业调用属性的job_type

dbms_scheduler.set_attribute( name => 'WINDPOWER.WIND_JOB_SGZY', attribute => 'job_type', value => 'PLSQL_BLOCK');

--修改作业调用属性的job_action

dbms_scheduler.set_attribute( name => 'WINDPOWER.WIND_JOB_SGZY', attribute => 'job_action', value => strSql );

--修改作业调用调度属性的start_date

dbms_scheduler.set_attribute(

name => 'WINDPOWER.WIND_JOB_SGZY',

attribute => 'start_date', value => to_timestamp_tz(calltime, 'YYYY-MM-DD HH24:MI:SS TZH:TZM'));

--修改作业调用属性使其可用

dbms_scheduler.enable( '"WINDPOWER"."WIND_JOB_SGZY"' );

END;

http://topic.csdn.net/u/20080827/09/f119d3bb-0df6-449c-9d1a-4c9e15f22f6e.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐