Click to See Complete Forum and Search --> : need help with PL/SQL


puneet
05-12-2003, 02:52 PM
I want to get the table names where the count (*) is different by num_rows by 20000 rows . Then I can analyze these tables . I have put the logic there , need some help with the code .


declare
a varchar(30),
b num,
c num ,
select table_name from user_tables into a where owner='SYSTEM',
select count(*) from a into b;
select num_rows into c from user_tables where table_name = a;
If b > c + 20000
Then
PRINT ' a'
/

slimdave
05-12-2003, 03:54 PM
Alternatively, you could ...

DBMS_STATS.ALTER_SCHEMA_TABLE_MONITORING
(
ownname => 'MY_SCHEMA'
);

... for all your tables in the schema, then periodically run ...

DBMS_STATS.GATHER_SCHEMA_STATS
(
...
options => 'GATHER STALE',
...
)

... which would hand over the task of deciding what tables needed re-analyzing to Oracle.

marcio.68
05-12-2003, 04:01 PM
Set pages 0
Spool e:\analize1.sql
Select 'Select ' || ''' Analyze Table ' || owner || '.' || table_name || ' Compute statistics;''' || ' from dual ' ||
' Where ' || num_rows || ' > (Select count(*) + 2000 from ' || owner || '.' || table_name || ');'
from dba_tables
;
spool off
spool e:\analize2.sql
@e:\analize1.sql
spool off
@e:\analize2.sql
Set pages 50