-
need help with PL/SQL
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'
/
-
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.
Last edited by slimdave; 05-12-2003 at 02:57 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
Márcio de Souza Almeida
DBA Oracle / SQLServer / PostgreSQL
Rua Cupa, 139 Apto 85 A
Penha - São Paulo - SP
03640-000 - Brasil
http://www.directory.com.br
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|