Monday, March 15, 2010

Varchar Vs Varchar2

If we declare datatype as VARCHAR then it will occupy space for NULL values, In case of VARCHAR2 datatype it will not occupy any space.
Varchar is of ANSI SQL standart while Varchar2 is of Oracle standard.
Varchar and Varchar2 both are of variable character. Varchar can have MAximum 2000 character while Varchar can contain maximum 4000 character.

VARCHAR(5) is fixed length, right padded with null.
VARCHAR2(5) is variable length.

Char Vs Varchar

The char is a fixed-length character data type, the varchar is a variable-length character data type.

Because char is a fixed-length data type, the storage size of the char value is equal to the maximum size for this column. Because varchar is a variable-length data type, the storage size of the varchar value is the actual length of the data entered, not the maximum size for this column.

You can use char when the data entries in a column are expected to be the same size.
You can use varchar when the data entries in a column are expected to vary considerably in size.

CHAR(5) is fixed length, right padded with spaces.
VARCHAR(5) is fixed length, right padded with null