Question: I need to get the length of a
particular row in Oracle. I am not aware of how to collect
size(bytes) for a particular row.
I know that I can use dbms_stats to get the
avg_row_len,
but I need to compute the actual row length for a specific row.
I don’t just need the data space used by a row, I want to know
the actual space consumed, a real row length. I need to actual row
length, not a guess or an average.
Answer: For detailed row length internals,
you must use BBED
and look inside the block data structures, count the internal
pointer and data space used by the row.
Here is a working example of computing the row length in a case
where the name and datatype of each row are known in advance:
select
nvl(dbms_lob.getlength(CASE_DATA),0)+1 +
nvl(vsize(CASE_NUMBER ),0)+1 +
nvl(vsize(CASE_DATA_NAME),0)+1 +
nvl(vsize(LASTMOD_TIME_T),0)+1
"Total bytes per row"
from
mytab
where
case = 123;
You will also see free-space at the end of a data block (as
defined by PCTFREE or ASSM, and you may also need to dump multiple
data blocks of the row is chained (fragmented) into multiple data
blocks.
Here is a PL/SQL procedure that
sums
individual row lengths to compute the average row length on
demand.
For any particular row, you can compute the row length by summing
these values for each row column, and guess by simply looking at the
datatype.
- VARCHAR row size: A VARCHAR2 you can use a length
function, and you can also use instr and nvl(vsize) to see a
string length:
select
length(last_name)
from
emp
where emp_id = 123;
select
nvl(vsize(last_name),0),
from
emp where emp_id = 123;
- NUMBER row size: For a number data type, you can see
the precision, and guess the actual bytes used
- For a CLOB you can use the
dbms_lob.get_length function
|
|
|
|
Guarantee your Success!
Oracle is the
world's most complex, robust and flexible database, considered
impossible to master without a mentor.
That's why all BC
Oracle trainers are working professionals, experts in Oracle who
share their tips and secrets. |
|
| |
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright ? 1996 - 2012
All rights reserved.
Oracle ?
is the registered trademark of Oracle Corporation.
|
|