Oracle 統(tǒng)計(jì)用戶下表的數(shù)據(jù)量實(shí)現(xiàn)腳本
要想統(tǒng)計(jì)用戶下所有表的數(shù)據(jù)量,可以查看user_tables,此表里面是統(tǒng)計(jì)信息,當(dāng)然這個(gè)可能不太準(zhǔn),要想非常精確,需要直接count表。下面的腳本有異常不中斷,可以重復(fù)執(zhí)行的特點(diǎn)。
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; /
總結(jié)
以上所述是小編給大家介紹的Oracle 統(tǒng)計(jì)用戶下表的數(shù)據(jù)量實(shí)現(xiàn)腳本,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- PDO取Oracle lob大字段,當(dāng)數(shù)據(jù)量太大無(wú)法取出的問(wèn)題的解決辦法
- Oracle 12c新特性之如何檢測(cè)有用的多列統(tǒng)計(jì)信息詳解
- Oracle 11g收集多列統(tǒng)計(jì)信息詳解
- Oracle Translate 統(tǒng)計(jì)字符出現(xiàn)的次數(shù)示例代碼
- Oracle數(shù)據(jù)庫(kù)按時(shí)間進(jìn)行分組統(tǒng)計(jì)數(shù)據(jù)的方法
- oracle表空間中空表統(tǒng)計(jì)方法示例介紹
- oracle數(shù)據(jù)庫(kù)下統(tǒng)計(jì)專營(yíng)店的男女?dāng)?shù)量的語(yǔ)句
相關(guān)文章
oracle實(shí)現(xiàn)動(dòng)態(tài)查詢前一天早八點(diǎn)到當(dāng)天早八點(diǎn)的數(shù)據(jù)功能示例
這篇文章主要介紹了oracle實(shí)現(xiàn)動(dòng)態(tài)查詢前一天早八點(diǎn)到當(dāng)天早八點(diǎn)的數(shù)據(jù)功能,涉及Oracle針對(duì)日期時(shí)間的運(yùn)算與查詢相關(guān)操作技巧,需要的朋友可以參考下2019-10-10深入淺析Orcale的nvl函數(shù)和SQL Server的isnull函數(shù)
這篇文章主要介紹了Orcale的nvl函數(shù)和SQL Server的isnull函數(shù)的相關(guān)資料,需要的朋友可以參考下2017-10-10oracle基礎(chǔ)教程之多表關(guān)聯(lián)查詢
在實(shí)際開(kāi)發(fā)中每個(gè)表的信息都不是獨(dú)立的,而是若干個(gè)表之間存在一定的聯(lián)系,如果用戶查詢某一個(gè)表的信息時(shí),可能需要查詢關(guān)聯(lián)表的信息,這就是多表關(guān)聯(lián)查詢,這篇文章主要給大家介紹了關(guān)于oracle基礎(chǔ)教程之多表關(guān)聯(lián)查詢的相關(guān)資料,需要的朋友可以參考下2023-12-12Oracle數(shù)據(jù)庫(kù)優(yōu)化策略總結(jié)篇
本文介紹了一些很實(shí)用但卻不是很常見(jiàn)的Oracle數(shù)據(jù)庫(kù)的優(yōu)化策略,包括批量FETCH、SQL預(yù)解析等,需要的朋友可以參考下2015-08-08Orancle的SQL語(yǔ)句之多表查詢和組函數(shù)
這篇文章主要介紹了Orancle的SQL語(yǔ)句之多表查詢和組函數(shù)的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-11-11Oracle 數(shù)據(jù)庫(kù)針對(duì)表主鍵列并發(fā)導(dǎo)致行級(jí)鎖簡(jiǎn)單演示
本文簡(jiǎn)單演示針對(duì)表主鍵并發(fā)導(dǎo)致的行級(jí)鎖,鎖的產(chǎn)生是因?yàn)椴l(fā)。沒(méi)有并發(fā),就沒(méi)有鎖。并發(fā)的產(chǎn)生是因?yàn)橄到y(tǒng)需要,系統(tǒng)需要是因?yàn)橛脩粜枰?,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03Oracle進(jìn)程占用CPU100%的問(wèn)題分析及解決方法
這篇文章主要介紹了Oracle進(jìn)程占用CPU100%的問(wèn)題分析及解決方法,文中通過(guò)代碼示例和圖文結(jié)合的方式給大家講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-08-08