計算表資料真實行長度獲得表真實大小
表存在很久後統計資料可能會不準需要計算行長度以期獲得表的真實大小
指令碼思路計算出沒列的平均長度相加然後乘以總行數獲得真實表資料大小。
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
- 【資料泵】EXPDP匯出表結構(真實案例)
- 達夢資料庫獲取SQL真實的執行計劃資料庫SQL
- 如何獲取真實的執行計劃
- 如何用JavaScript獲取圖片的真實尺寸大小JavaScript
- 獲取真實IP地址
- javascript獲取圖片的真實寬度和高度JavaScript
- 理解維度資料倉儲——事實表、維度表、聚合表
- 實現報表資料預先計算
- 如何獲取 PostgreSQL 資料庫中的表大小、資料庫大小、索引大小、模式大小、表空間大小、列大小SQL資料庫索引模式
- PHP獲得真實客戶端的真實IPREMOTE_ADDR,HTTP_CLIENT_IP,HTTP_X_FORWARDED_FORPHP客戶端REMHTTPclientForward
- 中國人月收入真實資料
- 獲取資料庫表的資訊(大小,索引大小,建立時間,行數)資料庫索引
- nginx後端獲取真實ipNginx後端
- Apapche獲取真實IP地址方法
- 獲取客戶端真實IP客戶端
- 【資料庫設計—接觸真實的的你】資料庫
- ACCESS 在資料表中實現簡單計算
- iPhone的真實成本–資料資訊圖iPhone
- 認真規劃外包關係將獲得長期回報(轉)
- 【資料倉儲】|4 維度建模之事實表設計
- 【資料倉儲】全量表、快照表、增量表、拉鍊表、維度表、實體表、事實表
- .net 獲取客戶端真實ip客戶端
- java 獲取客戶端真實ipJava客戶端
- 獲取使用者的真實ip
- Java/JSP獲得客戶端網路卡MAC地址的三種方法解析(附:獲得真實IP)JavaJS客戶端Mac
- 『B站:2018年度彈幕 “真實”獲得年度最佳』今日資料行業日報(2018.12.28)行業
- 一個真實的案例,一些真實存在的資料庫選型誤區資料庫
- Oracle如何檢視真實執行計劃(一)Oracle
- 關於房事的真實生活大資料大資料
- laravel symfony request獲取真實ip的坑Laravel
- PHP 獲取使用者真實的ipPHP
- js如何獲取圖片的真實尺寸JS
- jboss 獲取web專案真實路徑Web
- java 匿名 泛型 獲取真實類名Java泛型
- 鮮花:真實