zoukankan      html  css  js  c++  java
  • Script: Computing Table Size

    This script calculates the average row size for all tables in a schema. It generates a script (getAvgCol.sql) from USER_TABLES and then runs it. The following type of SELECT is generated for each table in USER_TABLES: SELECT round(avg(nvl(vsize(COL1),0)) + round(avg(nvl(vsize(COL2),0)) + ... + round(avg(nvl(vsize(COLn),0)) Where n=# of cols. on the table Tables with LONG and LOB columns will not report row size properly. Also tables with object types will throw the following error and will also not report row size properly: ORA-00932: inconsistent datatypes ============= Sample Output ============= ACCOUNTS 6 ACCTS 39 ACCT_ADDRS 38 BAD_DATA 116 BASE1 6 BONUS CEG1 11 CHESS_SAVE CHESS_SAVE_PLAYER CITIES 36 COMPANY_SUMMARY 60 CR_FILES 113

    Script:

    SET ECHO off
    REM NAME:   ROWSZ.SQL
    
    drop table column_counts;
    create table column_counts
            (
            table_name,
            column_count
            )
            as
            (
            select table_name, max(column_id)
            from user_tab_columns
            where data_type not like 'LONG%' AND table_name in
            (select table_name from user_tables)
            group by table_name
            )
            ;
    set pages 0
    set tab on
    set trim on
    set verify off
    set feedback off
    set termout off
    set head off
    set lines 100
    set recsep off
    set embedded on
    spool getavgcol.sql
    prompt column TB format A30
    prompt set head off recsep off
    prompt set lines 80 feedback off pages 0
    prompt spool getavgcol
    REM
    column select_line format A8
    column end_line format A1
    column from_stmt format A34 word_wrap
    column col_nm format A100
    column col_val format A32
    column tnm1 noprint
    column tnmprint format A37
    column column_id noprint
    break on tnm1 skip 2
    set null ''
    clear breaks
    select UTC.table_name tnm1,
            decode(column_id,1,'select ' || chr(39) || UTC.table_name || chr(39) ||
                    ' TB, ', '        ') ||
            'round(avg(nvl(vsize('||column_name||'),0)),0)' ||
            decode(column_id,column_count, ' row_size from ' || UTC.table_name
                 || ';'|| chr(10)||chr(10),
                    ' +') col_nm
    from user_tab_columns UTC, column_counts CC
    where UTC.data_type not like 'LONG%' AND UTC.table_name = CC.table_name
    order by UTC.table_name, UTC.column_id;
    prompt spool off
    prompt exit
    spool off
    drop table column_counts;
    exit
  • 相关阅读:
    C++_标准模板库STL概念介绍2-泛型编程
    C++_标准模板库STL概念介绍1-建立感性认知
    C++_新特性1-类型转换运算符
    C++_新特性2-RTTI运行阶段类型识别
    C++_异常9-异常的注意事项
    C++_异常8-异常、类和基础
    C++_异常7-exception类
    C++_异常6-其他异常特性
    redis数据类型之—List
    redis数据类型之—Hash
  • 原文地址:https://www.cnblogs.com/macleanoracle/p/2967199.html
Copyright © 2011-2022 走看看