Re: char vs varchar ?

From: troy trimble <troyt_at_sun.com>
Date: 1995/04/20
Message-ID: <3n5v0o$9hq_at_theopolis.orl.mmc.com>#1/1


In article 2F93BEDA_at_ctt.bellcore.com, vkj_at_ctt.bellcore.com (Vinod Jain) writes:
>Hi,
>
>I want to know if there are any advantages of using "char" over "varchar" in
>Oracle tables or vice-versa. Which datatype is better ? I am working on an
>application which is using Powerbuilder as front end and Oracle 7.1.4 as
>backend. Does Powerbuilder give any problems with char field types ?
>
>I am mainly a Sybase person and Sybase encourages use of char fields over
>varchar fields, particularly if the field is short (say less than 10 characters), since
>varchar adds overhead.

For fields of any real length, say 15 or more, VARCHAR2 is highly recommended. First, you have a maximum length of 2000, not 255. Also, VARCHAR2 fields occupy only as much space as their contents require while CHAR fields are right-padded with spaces to fill out the length of the field. For example, a 20-character string will occupy 20 (21?) bytes in a VARCHAR2(100) field and will occupy 100 bytes in a CHAR(100) field. This may help speed up record access due to the smaller stored record size.

Because of the right-end padding, comparing CHAR strings of different lengths can be a headache, even if they contain the same text, due to the extra spaces on the end of the strings. VARCHAR2 comparisons don't have this problem.

Enjoy,
TT Received on Thu Apr 20 1995 - 00:00:00 CEST

Original text of this message