Oracle - How do I get the actual size of a specific ROW?

后端 未结 3 1385
挽巷
挽巷 2020-12-29 09:00

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

相关标签:
3条回答
  • 2020-12-29 09:06

    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;
    /
    
    0 讨论(0)
  • 2020-12-29 09:21

    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.

    0 讨论(0)
  • 2020-12-29 09:25
    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

    0 讨论(0)
提交回复
热议问题