Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

dbms_lob.getlength tips

Oracle Database Tips by Donald BurlesonOctober 30, 2015

Question:  I want to understand how to use dbms_lob.getlength to estimate the size of a BLOB column in my table.  Are there issues with using dbms_lob.getlength?

Answer:  First, there are several methods for getting the length of a BLOB, CLOB table column. Yes, there is one issue with dbms_lob.getlength where dbms_lob.getlength gives an incorrect answer, where dbms_lob.getlength does not give the correct BLOB size. In this case, you need to pass the argument within double quotes:

Below is a WRONG invocation of dbms_lob.getlength, using single quotes which will give you an incorrect answer:

select
   dbms_lob.getlength('XML_OUT_BEFORE_XSL')
from
   XDB_TEST1.SSZLOB
where
   XML_OUT_BEFORE_XSL is not null;

DBMS_LOB.GETLENGTH('XML_OUT_BEFORE_XSL')
---------------------------------------------
18 ---> This gives the total number of characters


The actual way is to call dbms_lob_getlength is by using double quote marks:

select
   dbms_lob.getlength("XML_OUT_BEFORE_XSL")
from
   XDB_TEST1.SSZLOB
where
   XML_OUT_BEFORE_XSL is not null;

DBMS_LOB.GETLENGTH(XML_OUT_BEFORE_XSL)
---------------------------------------------
8250

There are a few ways to compute the actual data length, but I prefer the dbms_lob package:

select
   dbms_lob.getlength("BLOB_TABLE")
from 
   blob_mytab
order by
   dbms_lob.getlength("BOB_TABLE") desc ;

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("BLOB_TABLE"),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;

Some people also try using the dba_lobs view as an alternative to dbms_lob.getlength:

select
   table_name,
   column_name,
   segment_name,
   a.bytes
from
   dba_segments a
join
   dba_lobs b
using (owner, segment_name)
where
   b.table_name = 'BLOB_TABLE';


 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

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.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster