17

Is this possible? Or at least I'm looking to have a list of the size of all rows in a table.

danboh
  • 758
  • 2
  • 11
  • 28

3 Answers3

26
select vsize(col1) + vsize(col2) + vsize(col3) + 
long_raw_length_function(long_col) + DBMS_LOB.GETLENGTH(blob_col) 
from table 
where id_col = id_val;

for the long_raw_length_function, see this Get the LENGTH of a LONG RAW

Community
  • 1
  • 1
bpgergo
  • 15,669
  • 5
  • 44
  • 68
9

if you're interested in the average row length, you could analyze the table (with the DBMS_STATS package), then query ALL_TABLES.avg_row_len.

Vincent Malgrat
  • 66,725
  • 9
  • 119
  • 171
  • It may return lower value than sum of column lengths in bytes. Does it reflect actual disk storage space taken by an average row? – Olexa Feb 04 '15 at 09:55
  • 2
    @olexa: It seems the `avg_row_len` column takes into account the [actual space occupied by data](https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1041629603947). In most cases, it should be larger than the average of the sum of the size of the individual columns since there is small overhead at the column level (for instance: NULL values take space when not at the end of a row). Of course if you're using compression it could be lower. – Vincent Malgrat Feb 04 '15 at 10:45
3

Here below is the query I have modified to get the table row length when you don't have any data. This can help you with Capacity planning for Environment setup:

SET serveroutput ON linesize 300
DECLARE
  v_max_size       NUMBER := 0;
  v_owner          VARCHAR2(30);
  v_table_name     VARCHAR2(30);
  v_data_type      VARCHAR2(30);
  v_data_length    NUMBER := 0;
  v_data_precision NUMBER := 0;
  CURSOR CUR_TABLE
  IS
    SELECT DISTINCT table_name
    FROM all_tab_columns
    WHERE owner='TMS_OWNER'
    AND table_name NOT LIKE 'VIEW%'
    ORDER BY table_name;
BEGIN
  FOR Tab IN CUR_TABLE
  LOOP
    v_table_name := Tab.table_name;
    v_max_size   := 0;
    FOR i        IN
    (SELECT owner,
      table_name,
      data_type,
      data_length,
      data_precision
    FROM all_tab_columns
    WHERE owner    ='TMS_OWNER'
    AND table_name = v_table_name
    )
    LOOP
      IF i.data_type = 'NUMBER' THEN
        v_max_size  := (v_max_size + i.data_precision);
      ELSE
        v_max_size := (v_max_size + i.data_length);
      END IF;
    END LOOP;
    dbms_output.put_line(chr(10));
    dbms_output.put_line('Table ='||v_table_name||', Max Record Size = '||v_max_size||' bytes');
  END LOOP;
END;
/
Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
  • It doesn't answer the question of the topic, because the physical size of a specific row is requested. This script will only show the theoretical logical max size based on dictionary, but not the resulting max physical size of a specific row. – D. Lohrsträter Jul 21 '22 at 14:33