我有这个PL / SQL并且工作正常,也发送了电子邮件。
BEGIN
FOR cur_rec IN
(select JOB, SCHEMA_USER, WHAT from dba_jobs where Broken = 'Y') LOOP
BEGIN
SCHEMA2.send_mail(
p_to => 'receive@test.com',
p_from => 'send@test.com',
p_subject => 'JOB Report',
p_message => 'Job name is: ' || cur_rec.what,
p_smtp_host => 'webmail.test.com');
END;
END LOOP;
END;
/
我需要每4小时安排一次PL / SQL执行,但是我不知道如何使用该代码创建作业或程序,我已经尝试了很多但仍然说:
已完成警告
对于构建工作或/和程序的任何帮助表示赞赏。
答案 0 :(得分:2)
begin
DBMS_SCHEDULER.CREATE_JOB (
job_name=>'my_job',
job_type=>'PLSQL_BLOCK',
job_action=>
'BEGIN
FOR cur_rec IN
(select JOB, SCHEMA_USER, WHAT from dba_jobs where Broken = ''Y'') LOOP
BEGIN
SCHEMA2.send_mail(
p_to => ''receive@test.com'',
p_from => ''send@test.com'',
p_subject => ''JOB Report'',
p_message => ''Job name is: '' || cur_rec.what,
p_smtp_host => ''webmail.test.com'');
END;
END LOOP;
END;',
start_date=>sysdate+1, --start tomorrow at this time
repeat_interval=>'FREQ=HOURLY; INTERVAL=4', --repeat every 4 hours
auto_drop=>false
);
end;
/
查看其他选项的文档.. create job