--创建存储过程 create procedure analyze_table_elan4 is --analyze_table_elan4 存储过程名,自定义 begin dbms_stats.gather_schema_stats( ownname =>'ELAN', --修改要收集统计信息的用户 options => 'GATHER', estimate_percent => dbms_stats.auto_sample_size, method_opt => 'for all columns size skewonly', degree => 7 ); end analyze_table_elan4; --存储过程名保持一致 DECLARE job_id number; BEGIN SYS.DBMS_JOB.SUBMIT ( job => job_id ,what => 'analyze_table_elan4;' --调用存储过程 ,next_date => sysdate ,interval =>'TRUNC(SYSDATE + 1)' --每天12点执行 ,no_parse => TRUE ); SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(job_id)); COMMIT; END;
--查看job select * from dba_jobs;
查看刚才创建的job的id
--创建完成后,手动执行存储过程一次 declare begin DBMS_JOB.RUN(22); end; / --删除job begin dbms_job.remove(22); end; / --查看表收集统计信息时间 alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'; select num_rows, blocks, last_analyzed from dba_tables where table_name = 'T1';
标签:收集,--,JOB,job,table,定时,analyze,id From: https://www.cnblogs.com/elanjie/p/17314637.html