如何在Orcal中定时执行存储过程?(100分)

  • 主题发起人 主题发起人 xmd
  • 开始时间 开始时间
X

xmd

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾,小弟有一问题想请教各位。问题是这样:让Orcal中定时执行存储过程(如每
个月末自动执行清表工作),就象WIN98ZL中的计划任务一样,期待着你的回答,谢谢!
 
妳寫個JOB不就行暸么
 
一个例子
declare
v_jobname NUMBER;
v_date DATE;
BEGIN
v_date:=TRUNC(SYSDATE,'hh');
DBMS_JOB.SUBMIT(v_jobname,'QC_p_consulthlf;',v_date,'SYSDATE+1/24');

v_date:=trunc(sysdate,'dd')+23/24;
DBMS_JOB.SUBMIT(v_jobname,'QC_pBillHlf;',v_date,'SYSDATE+1');

COMMIT;
END;
/

所提交到任务是被后台SNP进程运行的。
提交
DBMS_JOB.SUBMIT( job OUT BINARY_INTEGER,
what IN VARCHAR2,
next_date IN DATE DEFAULT SYSDATE,
interval IN VARCHAR2 DEFAULT 'null',
no_parse IN BOOLEAN DEFAULT FALSE)
job: This is the identifier assigned to the job you created. You must use the job
number whenever you want to alter or remove the job.
what: This is the PL/SQL code you want to have executed
next_date: This is the next date when the job will be run. The default value is SYSDATE.
interval: This is the date function that calculates the next time to execute the job. The
default value is NULL. INTERVAL must evaluate to a future point in time or NULL
no_parse: This is a flag. The default value is FALSE. FALSE means the job code will be
analyse just after this job been submit.
删除
DBMS_JOB.REMOVE(job IN BINARY_INTEGER)

example DBMS_JOB.REMOVE(14144);
改变
DBMS_JOB.CHANGE( job IN BINARY_INTEGER,
what IN VARCHAR2,
next_date IN DATE,
interval IN VARCHAR2)
example: DBMS_JOB.CHANGE(14144, null, null, 'SYSDATE + 3');
DBMS_JOB.WHAT (job IN BINARY_INTEGER,
what IN VARCHAR2)
DBMS_JOB.NEXT_DATE (job IN BINARY_INTEGER,
next_date IN DATE)
DBMS_JOB.INTERVAL (job IN BINARY_INTEGER,
interval IN VARCHAR2)
执行
DBMS_JOB.RUN(job IN BINARY_INTEGER) 立即运行该任务(不SNP运行启动的)
失效作业(失败16次则标识为实效的broken)
DBMS_JOB.BROKEN ( job IN BINARY_INTERER,
broken IN BOOLEAN, --TRUE则标识为失效
next_date IN DATE DEFAULT SYSDATE)
 
DBMS_JOB只有在搞版本的Oracle中才有,
Oracle V8以上.

其实可以用Oracle加上操作系统的定时器功能就可以做到这一点.

WIN系列(AT命令)
UNIX(CRONTAB命令)

 
比如你的存贮过程是 myproc
那么,
declare
j integer;
begin
dbms_job.submit(j,'myproc',trunc(add_months(sysdate,1),'mm'),
'trunc(add_months(sysdate,1),''mm'')');
end;
/
下个月一号的00:00开始,每月1日的00:00执行
 
多人接受答案了。
 
后退
顶部