CHAR vs VARCHAR
Probably because of my FoxPro background, I had always thought that CHAR(n) allocated space for n characters and would pad any input to that length while VARCHAR(n) would simply store the input and perhaps truncate trailing spaces.
It seems that I have this backwards.
CREATE TEMPORARY TABLE xx (f1 CHAR(10), f2 VARCHAR(10))
INSERT INTO xx VALUES ("1","1")
INSERT INTO xx VALUES ("2 ","2 ")
SELECT LENGTH(f1),LENGTH(f2) from xx;
length(f1) Length(f2)
1 1
1 6
Is there any reason to use VARCHAR for fields shorter than 256 characters?
How is disk space calculated for CHAR and VARCHAR fields?
Is this same behavior seen in SQL-Server, Oracle, DB2, Postgres, etc?
Thanks for all responses.
Subject
Written By
Posted
CHAR vs VARCHAR
April 19, 2012 07:13PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.