need help with PL/SQL
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: need help with PL/SQL

  1. #1
    Join Date
    Nov 1999
    Posts
    226

    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'
    /

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    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.
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  3. #3
    Join Date
    Dec 2000
    Location
    Brazil / São Paulo
    Posts
    97
    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
  •  



Click Here to Expand Forum to Full Width