Oracle 统计用户下表的数据量实现脚本
要想统计用户下所有表的数据量,可以查看user_tables,此表里面是统计信息,当然这个可能不太准,要想非常精确,需要直接count表。下面的脚本有异常不中断,可以重复执行的特点。
createtablebk_count_tables ( ownerVARCHAR2(30), table_nameVARCHAR2(30), part_colvarchar2(100),--分区字段 row_snumber, gather_timedate ); createindexind_bct_own_tableonbk_count_tables(owner,table_name); setserveroutputon declare cursorc_cursorisselects.OWNER,s.TABLE_NAME,col.column_namepart_col fromdba_tabless, (selectowner, name, listagg(column_name,',')withingroup(orderbynull)column_name from(selectowner,name,column_name fromdba_part_key_columns whereownerin('TEST') andobject_type='TABLE' andnamenotlike'BIN$%' unionall selectowner,name,column_name fromdba_subpart_key_columns whereownerin('TEST') andobject_type='TABLE' andnamenotlike'BIN$%') groupbyowner,name)col wheres.OWNERin('TEST') andnotregexp_like(table_name,'[0-9]{3,8}') ands.table_namenotlike'%BAK%' ands.table_namenotlike'%A2K%' ands.table_namenotlike'BK%' ands.table_namenotlike'BIN%' ands.OWNER=col.owner(+) ands.TABLE_NAME=col.name(+) orderbys.TABLE_NAME; c_rowc_cursor%rowtype; t_rowsnumber; begin forc_rowinc_cursorloop begin executeimmediate'selectcount(*)frombk_count_tableswhereowner=:1andTABLE_NAME=:2andrownum=1' intot_rowsusingc_row.OWNER,c_row.TABLE_NAME; if(t_rows=0)then executeimmediate'selectcount(*)from"'||c_row.TABLE_NAME||'"'intot_rows; insertintobk_count_tablesvalues(c_row.OWNER,c_row.TABLE_NAME,c_row.part_col,t_rows,sysdate); commit; endif; EXCEPTION WHENOTHERSTHEN DBMS_OUTPUT.PUT_LINE(c_row.OWNER||'---'||c_row.TABLE_NAME); rollback; end; endloop; end; /
总结
以上所述是小编给大家介绍的Oracle统计用户下表的数据量实现脚本,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!