dbms_lob.getlength() vs. length() to find blob size in oracle
SqlOracleBlobSql Problem Overview
I'm getting the same results from
select length(column_name) from table
as
select dbms_lob.getlength(column_name) from table
However, the answers to
https://stackoverflow.com/questions/840966/what-is-an-elegant-way-to-return-a-readable-file-size-of-a-file-stored-in-an-or">this question seem to favor using dbms_lob.getlength()
.
Is there any benefit to using dbms_lob.getlength()
?
If it changes the answer, I know all of the blobs are .bmp images (never worked with blobs before).
Sql Solutions
Solution 1 - Sql
[length
][1] and [dbms_lob.getlength
][2] return the number of characters when applied to a CLOB (Character LOB). When applied to a BLOB (Binary LOB), dbms_lob.getlength
will return the number of bytes, which may differ from the number of characters in a multi-byte character set.
As the documentation doesn't specify what happens when you apply length
on a BLOB, I would advise against using it in that case. If you want the number of bytes in a BLOB, use dbms_lob.getlength
.
[1]: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions076.htm#i77725 "LENGTH 10gR2" [2]: http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998484