create or replace procedure PROC_TEST
-- Authid Current_User必须要添加,否则权限不足
Authid Current_User
is
v_error varchar2(1000);
begin
execute immediate 'create table user as select * from teacher where 1 != 1';
commit;
exception
when others then
-- 这里输出异常信息
v_error := sqlerrm;
-- 这一步的目的是如果发生异常,就将异常信息写入job_log表中
insert into job_log values (sys_guid(), sysdate,'PROC_TEST', v_error);
end PROC_TEST;
2、编写job
declare
-- Local variables here
job number;
begin
-- Test statements here
-- trunc(last_day(sysdate)) + (23*60+5)/(24*60) 是指每月最后一天晚上23:05分执行,存储过程名称后面必须添加“;”分号!!!
dbms_job.submit(job, 'proc_gather_device;', trunc(last_day(sysdate)) + (23*60+5)/(24*60), 'trunc(last_day(sysdate)) + (23*60+5)/(24*60)');
commit;
end;