Varchar vs CLOB

devman

2[H]4U
Joined
Dec 3, 2005
Messages
2,400
Could one of you db guru's explain to me the finer points of clob vs. varchar. I know what they are but the info I'm looking for is performance characteristics, storage space, etc.

I'm gonna take a wild guess and say that some of this is probably implementation dependent, but I was hoping someone could speak to it in a general sense.

In this specific case I'm using Apache Derby, and I'm storing about 5 or 6 pages (it varies) worth of text (if you were to print it) UTF-8 encoding per record.
 
Could one of you db guru's explain to me the finer points of clob vs. varchar. I know what they are but the info I'm looking for is performance characteristics, storage space, etc.

I'm gonna take a wild guess and say that some of this is probably implementation dependent, but I was hoping someone could speak to it in a general sense.

In this specific case I'm using Apache Derby, and I'm storing about 5 or 6 pages (it varies) worth of text (if you were to print it) UTF-8 encoding per record.

NOTE: Below info is based on Oracle, I am not familiar with Derby however some of this may apply to derby.

Well general speaking you can not use a clob in select statements the same way you can with a varchar. In fact in Oracle you are pretty much limited to just being able to select the clob, you can not use a clob in a where,group by, distinct, and a few other statements and in many of the builtin functions that you can use a varchar for. You can however in Oracle convert a clob to a varchar2, however this will truncate the data to 4000 characters for Oracle. You can not use a clob as a primary key, foreign key or index.

Performance wise it depends on how Derby handles clobs. However chances are it handle varchar fields both faster and uses less space. If you know your data will fit in a varchar the use the varchar. It seems from googling Derby's varchar limit is 32K characters. That is a good bit of text. You need to define 5 or 6 pages a little better to know if it will fit, however 32K is 32,672 utf-8 characters.
 
Back
Top