Thursday, May 13, 2010

sql pl/sql interview questions

Q : What is the difference between CHAR and VARCHAR ?

A:
To understand this, I will give an example -- say you have defined two columns A and B of a table as CHAR(20) and VARCHAR(20) respectively. Now you enter data in both column as "abc".

For column A memory occupied will be of size 20 and for B will be only 3 (i.e. size of actual string data). VARCHAR will occupy memory as much as required by data while CHAR will pad the remaining 17 (20-3) with space and ultimately will use more memory even for smaller data.

Another difference is that CHAR is faster in operation then VARCHAR.