Create a procedure to collect statistics on all my objects : DBMS_STATS « System Packages « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> create table my_stats_table
  2  (object_name  varchar2(30),
  3   gather_date  date default sysdate);

Table created.

SQL>
SQL>
SQL> create or replace procedure gather_my_stats as
  2    olist  dbms_stats.objectTab;
  3  begin
  4    dbms_stats.gather_schema_stats(user,
  5            cascade=>TRUE,
  6            method_opt=> 'AUTO',
  7            options=>'GATHER AUTO',
  8            objlist=>olist);
  9
 10    if olist.COUNT > 0 then
 11       FOR x in 1..olist.COUNT LOOP
 12           insert into my_stats_table (object_name)
 13            values(olist(x).objname);
 14       END LOOP;
 15    end if;
 16  end;
 17  /

Procedure created.

SQL>
SQL>
SQL> select object_name, to_char(gather_Date, 'mm/dd/yyyy hh:mi')
  2  from my_Stats_table;

no rows selected

SQL>
SQL> drop table my_stats_table;



SQL>








31.27.DBMS_STATS
31.27.1.execute SYS.DBMS_STATS.gather_table_stats(USER, 'employee_job');
31.27.2.Check table status with SYS.DBMS_STATS.gather_table_stats after adding index
31.27.3.Create a procedure to collect statistics on all my objects
31.27.4.dbms_stats.drop_stat_table, dbms_stats.create_stat_table,dbms_stats.delete_system_stats
31.27.5.dbms_stats.gather_schema_stats
31.27.6.dbms_stats.gather_table_stats
31.27.7.dbms_stats.import_system_stats
31.27.8.dbms_stats.objectTab
31.27.9.dbms_stats.set_table_stats( user, 'EMP', numrows => 100000 )
31.27.10.dbms_stats.set_table_stats( user, 'myTable1', numrows => 10000000, numblks => 1000000 )