I like to know what is better in terms of performance to use VARCHAR2(n) or CHAR datatype for column when creating and accessing tables.
Thanks in Advance
Printable View
I like to know what is better in terms of performance to use VARCHAR2(n) or CHAR datatype for column when creating and accessing tables.
Thanks in Advance
varchar2 will ofcourse save you some space.
for eg. datatype1 char2(4)
datatype2 varchar2(4)
insert into table values('AB', 'XY');
the length of char will be 4 and length of varchar2 willbe 2 in this case.
Although... if you have
CHAR(2)
And
VARCHAR2(2)
and the you know the value of the field will ALWAYS BE TWO. Then you'd be better of storing in a CHAR. VARCHAR2 use an extra byte to store the number of bytes used. In the example above... Char(2) would only use 2 bytes and Varchar2(2) would use 3.
Therefore valus that are always consistents, like Gender m/f, would be a good candidate for a CHAR(1) field.
Cheers,