BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'gather_schema',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN dbms_stats.gather_schema_stats(ownname=>''DBA_FID'', estimate_percent=> 10, method_opt=> ''for all columns size auto'',degree=> 1); END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=DAILY;byhour=03;byminute=0;',
end_date => NULL,
enabled => TRUE,
comments => 'Gather schema DBA_FID tous les jours a 3h');
END;
/
# Attention, il s'agit de 2 simple quote et non une double quote autour de DBA_FID
CREATE OR REPLACE PROCEDURE SYS.REBUILD_TABLE_INDEX
AS
SQL_STR VARCHAR2(1000);
BEGIN
FOR CUROSR_INDEX IN (SELECT OWNER,INDEX_NAME from dba_indexes
WHERE OWNER='DBA_FID'
ORDER BY INDEX_NAME ) LOOP
BEGIN
SQL_STR:='ALTER INDEX '||CUROSR_INDEX.OWNER||'.'||CUROSR_INDEX.INDEX_NAME ||' REBUILD NOLOGGING';
EXECUTE IMMEDIATE SQL_STR;
DBMS_OUTPUT.PUT_LINE('SUCCESS : '|| CUROSR_INDEX.OWNER||'.'||CUROSR_INDEX.INDEX_NAME);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR : '||CUROSR_INDEX.OWNER||'.'||CUROSR_INDEX.INDEX_NAME||':'||SQLERRM);
END;
END LOOP;
END;
/
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'REBUILD_INDEX',
job_type => 'STORED_PROCEDURE',
job_action => 'REBUILD_TABLE_INDEX',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=DAILY;byday=MON;byhour=04;byminute=0;',
end_date => NULL,
enabled => TRUE,
comments => 'Rebuild index DBA_FID tous les lundi a 4h');
END;
/
BEGIN
dbms_scheduler.drop_job(job_name => 'REBUILD_INDEX');
END;
/
executer le job manuellement :
execute dbms_scheduler.run_job('REBUILD_INDEX');
SELECT OPERATION, JOB_NAME, STATUS FROM DBA_OPTSTAT_OPERATIONS ORDER BY START_TIME;
SELECT job_name, log_date, status, actual_start_date, run_duration, cpu_used FROM dba_scheduler_job_run_details where job_name like '%GATHER%';