28 07 2010

What is the difference between CLOB and BLOB ?

A BLOB is a binary large object, and a CLOB is a
character large object. The difference between characters and bytes is the
Character set, i.e. the mapping between a character and the byte sequence
it represents.
- With a blob, you have to use the right character set to retrive the data,
e.g. if someone writes a text into a BLOB using UTF-8 and you read it back
using ISO-8859-1, you do not get the same string back out.
- With a CLOB, the database takes care of the character set, you supply a
String, and you get a String back, and you do not have to worry about which
bytes are used to represent the characters. in fact, you do not have access
to the byte represetnation, so its uselessi if you want to store bytes.

So in any other database, if you want to store large text, use a CLOB, if
you want to store an image, use a BLOB.

Having said this, it seems to me (although I did not research it) that the
Oracle drivers specify a default character set even for BLOBs, the method
oracle.sql.BLOB.characterStreamValue() seems to do this(I never used it).
So a Oracle BLOB can also be used with CLOB functionality. Looking at the
jdbc specification, this seems to be a oracle-specific extension. It seems
tom me that it is only a oracle-specific _jdbc_ extension. E.g. you cannot
display a BLOB on console, whereas you can display a CLOB.

So the short answer is, if you only use an oracle database and only use
oracle jdbc, you can also use BLOBs for text. If you want other access
(e.g. sqlplus(console)) access to the text you stored, use a CLOB.
I would consider it cleaner if one would always use a CLOB for text (Rather
rely on standards as opposed to vendor-specific extensions)

0 yorum:

Share It