Обращаю внимание, что существует механизм назначенных заданий dbms_scheduler (появился с 10ки, если не ошибаюсь).
Список заданий можно посмотреть
Код:
select * from dba_scheduler_jobs
вот пример определения заданий
Код:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'smpackupd_job',
job_type => 'PLSQL_BLOCK',
job_action => 'begin smpackupd; end;',
repeat_interval => 'freq=daily;byhour=06;byminute=30;bysecond=0',
enabled => TRUE
);
END;
/
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'kill_old_sessions',
job_type => 'PLSQL_BLOCK',
job_action => 'begin kill_old; end;',
repeat_interval => 'freq=daily;byhour=22;byminute=29;bysecond=0',
enabled => TRUE
);
END;
/
create or replace procedure kill_old is
begin
for c in (select sid, serial#
from v$session
where resource_consumer_group in
('LOW_GROUP', 'DEFAULT_CONSUMER_GROUP', 'ANAL',
'OTHER_GROUPS')) loop
begin
execute immediate 'alter system disconnect session ''' || c.sid || ',' ||
c.serial# || ''' immediate';
exception
when others then
null;
end;
end loop;
end;
-- предпоследний день месяца
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'mv_update_430',
job_type => 'PLSQL_BLOCK',
job_action => 'begin dbms_mview.refresh(''"FDC_EXEC"."FDC_MV_REPORT_430"''); end;',
repeat_interval => 'FREQ=MONTHLY; BYMONTHDAY=-2',
enabled => TRUE
);
END;
/
-- В окне, с прерыванием по его завершению
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'global_opt',
job_type => 'PLSQL_BLOCK',
schedule_name => 'WEEKEND_WINDOW',
job_action => '
begin
for c in (select owner,table_name from all_tables where owner not in (''SYS'',''SYSTEM''))
loop
begin
execute immediate ''alter table ''||c.owner||''.'' || c.table_name || '' enable row movement'';
execute immediate ''alter table ''||c.owner||''.'' || c.table_name || '' deallocate unused keep 0'';
execute immediate ''alter table ''||c.owner||''.'' || c.table_name || '' shrink space cascade compact'';
execute immediate ''alter table ''||c.owner||''.'' || c.table_name || '' shrink space cascade'';
execute immediate ''alter table ''||c.owner||''.'' || c.table_name || '' deallocate unused keep 0'';
exception when others then null;
end;
end loop;
DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;
DBMS_STATS.gather_database_stats(estimate_percent => 15, cascade => true, degree=>6);
end;',
enabled => TRUE
);
DBMS_SCHEDULER.SET_ATTRIBUTE(
NAME => 'global_opt',
ATTRIBUTE => 'STOP_ON_WINDOW_CLOSE',
VALUE => TRUE
);
END;
/
begin
dbms_scheduler.drop_job('GLOBAL_OPT');
end;
Пример создания scheduler_job