Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: CHAR vs VARCHAR
Paul Pruchnik wrote:
> Greetings,
> What is the savings of CHAR(4) vs VARCHAR(4) for storing a 4 (required)
> character code? What is the overhead in using VARCHAR for fields of required
> length?
> Thanks,
> -Paul Pruchnik
When you say "4 (required)", can we state that there are 4 non-blank characters? And there will NEVER be any trailing blanks?
My observations and opinions on using CHAR(4)
- it adds a non-coded constraint to ensure that all 4 bytes will be used. - it is very rarely used in any application code - there may be am indexing benefit (precalc. block structures), but I'd guess itis so rarely used that the developers simply wouldn't bother
- it will help in your size calculations - helps avoid the "is it NULL or just empty?" issue. - since a non-Null entry MUST be the right size, a Null value byte "should" notbe required.
At the same time, virtually every [Oracle] programmer is familiar with the operations & assumptions of the VarChar2, and manby will get tripped up by the Char padding. So I suggest avoiding Char unless you can ensure that there will never be trailing blanks.
JIMHO/Hans Received on Wed Apr 02 2003 - 16:38:43 CST