1、编写procedure
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;
3、处理权限
上面的处理办法在断点调试时毫无问题,但是让job自动执行就可能遇到问题,原因就是用户没有建表的权限!给相应用户指定的建表权限即可!
grant create table to MYUSER;
4、查看job状态
select * from user_jobs