計算表資料真實行長度獲得表真實大小
表存在很久後統計資料可能會不準需要計算行長度以期獲得表的真實大小
指令碼思路計算出沒列的平均長度相加然後乘以總行數獲得真實表資料大小。
select 'select ' ||(SELECT
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=1 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=2 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=3 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=4 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=5 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=6 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=7 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=8 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=9 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=10) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=11) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=12) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=13) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=14) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=15) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=16) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=17) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=18) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=19) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=20) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||') ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=21) --- 最後一行不需要逗號
FROM DUAL)||' from TABLE_NAME' from dual
註釋:第一步需要計算出 select count(COLUMN_NAME) from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME' 計算出這張表有多少列作為rn 的最大值
第二:在表中如果有CLOB NCLOB 列則需要將Lengthb(返回位元組數) 函式變成Length(返回字元數) 然後查處系統使用什麼字符集一個字元佔多少byte相乘
舉例如果有CLOB或者NCLOB 則那行需要變成
(select t.siz from (select rownum rn ,'AVG('||'Length('||COLUMN_NAME||')'||')*一個字元佔位元組數+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=N)
得出的行記錄 就可以拿出來執行獲得行的長度 再來計算表真實大小
指令碼思路計算出沒列的平均長度相加然後乘以總行數獲得真實表資料大小。
select 'select ' ||(SELECT
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=1 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=2 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=3 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=4 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=5 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=6 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=7 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=8 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=9 ) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=10) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=11) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=12) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=13) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=14) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=15) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=16) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=17) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=18) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=19) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||')+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=20) ||
(select t.siz from (select rownum rn ,'AVG('||'Lengthb('||COLUMN_NAME||')'||') ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=21) --- 最後一行不需要逗號
FROM DUAL)||' from TABLE_NAME' from dual
註釋:第一步需要計算出 select count(COLUMN_NAME) from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME' 計算出這張表有多少列作為rn 的最大值
第二:在表中如果有CLOB NCLOB 列則需要將Lengthb(返回位元組數) 函式變成Length(返回字元數) 然後查處系統使用什麼字符集一個字元佔多少byte相乘
舉例如果有CLOB或者NCLOB 則那行需要變成
(select t.siz from (select rownum rn ,'AVG('||'Length('||COLUMN_NAME||')'||')*一個字元佔位元組數+ ' siz from dba_tab_columns where table_name='TABLE_NAME' and owner='USERNAME') t where rn=N)
得出的行記錄 就可以拿出來執行獲得行的長度 再來計算表真實大小
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26764973/viewspace-1188879/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 檢視oracle資料庫真實大小Oracle資料庫
- jquery獲取圖片的真實大小jQuery
- JavaScript獲取圖片的真實大小JavaScript
- 『B站:2018年度彈幕 “真實”獲得年度最佳』今日資料行業日報(2018.12.28)行業
- 【資料泵】EXPDP匯出表結構(真實案例)
- 達夢資料庫獲取SQL真實的執行計劃資料庫SQL
- 用Python計算柵格資料的真實面積Python
- 如何獲取 PostgreSQL 資料庫中的表大小、資料庫大小、索引大小、模式大小、表空間大小、列大小SQL資料庫索引模式
- 實現報表資料預先計算
- ACCESS 在資料表中實現簡單計算
- 獲取客戶端真實IP客戶端
- 【資料倉儲】|4 維度建模之事實表設計
- 【資料倉儲】全量表、快照表、增量表、拉鍊表、維度表、實體表、事實表
- 中國人月收入真實資料
- .net 獲取客戶端真實ip客戶端
- Oracle如何檢視真實執行計劃(一)Oracle
- [20181120]toad看真實的執行計劃.txt
- 一個真實的案例,一些真實存在的資料庫選型誤區資料庫
- 報表資料外接計算
- 買真實銀行儲蓄卡
- java 匿名 泛型 獲取真實類名Java泛型
- laravel symfony request獲取真實ip的坑Laravel
- PHP 獲取使用者真實的ipPHP
- [轉帖]達夢資料庫-統計資料表資料量及空間表大小資料庫
- 在Oracle中,如何得到真實的執行計劃?Oracle
- ABP vNext 審計日誌獲取真實客戶端IP客戶端
- CSS 如何模擬“真實的”進度條?CSS
- 真 · 逃避現實
- 鮮花:真實
- 資料倉儲(8)數倉事實表和維度表技術
- 同時支援真實資料與 mock 資料的 httpmock 工具MockHTTP
- 【Go】獲取使用者真實的ip地址Go
- 【Go】獲取使用者真實的 ip 地址Go
- 伺服器獲取真實客戶端 IP伺服器客戶端
- [20210114]toad檢視真實執行計劃問題.txt
- 真實系統(Real systems)通常表現出空間變化(spatial variation)
- 【scikit-learn基礎】--『資料載入』之真實資料集
- 你不見得會計算C字串長度字串
- Node.js 解決Gzip下獲取真實的下載進度問題Node.js