Oracle 統(tǒng)計用戶下表的數(shù)據(jù)量實現(xiàn)腳本
要想統(tǒng)計用戶下所有表的數(shù)據(jù)量,可以查看user_tables,此表里面是統(tǒng)計信息,當然這個可能不太準,要想非常精確,需要直接count表。下面的腳本有異常不中斷,可以重復執(zhí)行的特點。
create table bk_count_tables ( owner VARCHAR2(30), table_name VARCHAR2(30), part_col varchar2(100),--分區(qū)字段 row_s number, gather_time date ); create index ind_bct_own_table on bk_count_tables(owner,table_name); set serveroutput on declare cursor c_cursor is select s.OWNER, s.TABLE_NAME, col.column_name part_col from dba_tables s, (select owner, name, listagg(column_name, ',') within group(order by null) column_name from (select owner, name, column_name from dba_part_key_columns where owner in ('TEST') and object_type = 'TABLE' and name not like 'BIN$%' union all select owner, name, column_name from dba_subpart_key_columns where owner in ('TEST') and object_type = 'TABLE' and name not like 'BIN$%') group by owner, name) col where s.OWNER in ('TEST') and not regexp_like(table_name, '[0-9]{3,8}') and s.table_name not like '%BAK%' and s.table_name not like '%A2K%' and s.table_name not like 'BK%' and s.table_name not like 'BIN%' and s.OWNER = col.owner(+) and s.TABLE_NAME = col.name(+) order by s.TABLE_NAME ; c_row c_cursor%rowtype; t_rows number; begin for c_row in c_cursor loop begin execute immediate 'select count(*) from bk_count_tables where owner=:1 and TABLE_NAME=:2 and rownum=1' into t_rows using c_row.OWNER,c_row.TABLE_NAME ; if(t_rows = 0) then execute immediate 'select count(*) from "'||c_row.TABLE_NAME||'"' into t_rows; insert into bk_count_tables values(c_row.OWNER,c_row.TABLE_NAME,c_row.part_col,t_rows,sysdate); commit; end if; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(c_row.OWNER||'---'||c_row.TABLE_NAME); rollback; end; end loop; end; /
總結
以上所述是小編給大家介紹的Oracle 統(tǒng)計用戶下表的數(shù)據(jù)量實現(xiàn)腳本,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
oracle實現(xiàn)動態(tài)查詢前一天早八點到當天早八點的數(shù)據(jù)功能示例
這篇文章主要介紹了oracle實現(xiàn)動態(tài)查詢前一天早八點到當天早八點的數(shù)據(jù)功能,涉及Oracle針對日期時間的運算與查詢相關操作技巧,需要的朋友可以參考下2019-10-10深入淺析Orcale的nvl函數(shù)和SQL Server的isnull函數(shù)
這篇文章主要介紹了Orcale的nvl函數(shù)和SQL Server的isnull函數(shù)的相關資料,需要的朋友可以參考下2017-10-10Oracle數(shù)據(jù)庫優(yōu)化策略總結篇
本文介紹了一些很實用但卻不是很常見的Oracle數(shù)據(jù)庫的優(yōu)化策略,包括批量FETCH、SQL預解析等,需要的朋友可以參考下2015-08-08Oracle 數(shù)據(jù)庫針對表主鍵列并發(fā)導致行級鎖簡單演示
本文簡單演示針對表主鍵并發(fā)導致的行級鎖,鎖的產(chǎn)生是因為并發(fā)。沒有并發(fā),就沒有鎖。并發(fā)的產(chǎn)生是因為系統(tǒng)需要,系統(tǒng)需要是因為用戶需要,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03