Re: char vs varchar2

From: Thomas J. Kyte <tkyte_at_us.oracle.com>
Date: 2000/07/01
Message-ID: <8jkv38$489$1_at_nnrp1.deja.com>#1/1


In article <8ji6im$5vc$1_at_nnrp1.deja.com>,   sybrandb_at_my-deja.com wrote:
> In article <i6475.298$Mb4.4252010507_at_news.euroconnect.net>,
> "Søren Junk" <sojudk_at_ifsas.dk> wrote:
> > The basic difference between char and varchar2 is, that a varchar2
 only
> > takes up the space it needs, and a char takes up the whole length
 (trailing
> > spaces are added).
> >
> > This means that if you have an empty string, the varchar2 will treat
 it as
> > an empty string, but a char will treat is a a number of spaces.
> >
> > Regards
> >
> > Søren Junk
>
> This is true but only half of the story. The varchar2 has 2 length
> bytes, AFAIK the char doesn´t include a length byte. So an empty
> varchar2(1) will take up more space than a char(1).
>
> Regards,
>

char = varchar2 as far as storage is concerned. A char is simply a blank padded varchar. It takes either 1 or 3 bytes to store the length:

char, varchar2, varchar, raw

[Quoted]  A 'small' character field is one that has a length of <= 250 characters. Anything else is considered as a 'long' character type.

[Quoted]  o Small Character

[Quoted]    1 byte for column length, followed by the data. Eg,

     03 nn nn nn

 o Long Character

   1 flag byte to tell us its "big", the next two bytes are used to store the *actual* length, and then followed by data. Eg,

    fe 01 34 nn nn nn

a char(1) and varchar2(1) are stored the same.

> >
> > gi <gi_at_england.com> wrote in message
> > news:nlZ65.2368$Dr3.145427_at_monolith.news.easynet.net...
> > > Can someone tell me ...but who really knows
> > > if I have filled with length is there any difference if I use char
 (1) or
> > > varchar2(1)
> > > I read somewhere that char is there only because COBOL programs
 but
 I'm
 not
> > > sure is that true
> > > Thanks
> > >
> > >
> >
> >
>
> --
> Sybrand Bakker, Oracle DBA
>
> All standard disclaimers apply
> ----------------------------------------------------------------------
 --
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

--
[Quoted] [Quoted] Thomas Kyte (tkyte_at_us.oracle.com) Oracle Service Industries
Howtos and such: http://osi.oracle.com/~tkyte/index.html
Oracle Magazine: http://www.oracle.com/oramag
Opinions are mine and do not necessarily reflect those of Oracle Corp


Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Sat Jul 01 2000 - 00:00:00 CEST

Original text of this message