Re: Char & Varchar2

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 1998/02/24
Message-ID: <34fb2f35.107655129_at_192.86.155.100>#1/1


A copy of this was sent to ts_at_chainsaw.ecn.purdue.edu (Thomas Ruschak) (if that email address didn't require changing) On 23 Feb 1998 22:20:50 GMT, you wrote:

>
> Hey, can anyone give me a quick couple of lines overview on when
>to use char & when varchar2? What are the overhead costs associated with
>varchar2?
>
> Any help appreciated...
>
>Thanks,
>Tom

[Quoted] Simply put, a CHAR is a VARCHAR2 that is blank padded to its maximum length. The are stored the same on disk.

A char and varchar2 are stored on disk in the same fashion -- both have a leading byte(s) to indicate their length. A CHAR(5) will always (when not null) take 5 bytes for the data plus 1 byte for the length. a Varchar2(5) with the value "ABC" will take 3 bytes for the data and 1 byte for the length.

A CHAR therefore, always consumes maximum storage. This is good and bad. Its bad in that it eats alot of space on disk. Good in that a varchar2, if updated frequently with values of different lengths, can cause a row to migrate or chain. A CHAR, since it takes maximum storage, will not cause a row to migrate (unless it goes from being NULL to NOT NULL that is).  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Bethesda MD  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Tue Feb 24 1998 - 00:00:00 CET

Original text of this message