Oracle表記錄位元組長長度的兩種計算方式

來源:互聯網
上載者:User

一、擷取某個使用者下Oracle某個表行記錄的長度

這個長度是表欄位定義的長度,擷取方法:

  1. select owner,  
  2.        table_name,  
  3.        column_name,  
  4.        data_type,  
  5.        data_length,  
  6.        sum(case data_type  
  7.              when 'DATE' then 
  8.               7  
  9.              when 'NUMBER' then 
  10.               22  
  11.              else 
  12.               data_length  
  13.            end) length  
  14.   from all_tab_cols  
  15.  where table_name = upper('表名')  
  16.    and DATA_TYPE  
  17.    and owner=upper('使用者名稱')  
  18.  group by rollup((owner, table_name, column_name, data_type, data_length)) 

二、根據表資料所佔總位元組數和表記錄數來擷取實際的每行記錄的平均長度

擷取表資料的所有位元組數:

  1. select segment_name,  
  2.        segment_type,  
  3.        nvl(sum(bytes), 0)     
  4.   from user_segments   
  5.  where segment_type = 'TABLE'   
  6.    and segment_name = '表名'   
  7.  group by segment_name, segment_type   
  8.  order by 3 desc; 

擷取表總記錄數:

select count(*) from 表名 

兩者求商即得每行記錄的平均位元組數。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.