+1 vote
61 views
i already know char means fixed length ,varchar means variable length..this also confused..can anyone explain??
asked Jan 6, 2016 in Computer Science - IT by gypsiii
retagged Jan 6, 2016 by gypsiii | 61 views

1 Answer

0 votes
Selected Ans.

Both Char & Varchar are datatypes that store data like numeric,characters or special characters ( non-Unicode character)

Maximum Size that can take :
CHAR    : 2000 bytes
VARCHAR    : 4000 bytes
https://docs.oracle.com/cd/B28359_01/server.111/b28320/limits001.htm

CHAR has a fixed length & also if data is less than assigned length then they are right padded with blanks.

CHAR:

Default length is one byte.

VARCHAR:

Default length is one byte.


For Example :
Consider string : "JOBS"

If we save the string using char(20)
Length of saved data with padded data will be 20

At the same time if we same using varchar(20)
Length of saved data will be 3 and not 20 since there is no extra padding.

If you are using datas that have some fixed length you can use CHAR ,but if they are varying use varchar.
For example using varying length data with char can result in space wastage.

The fact that a CHAR/NCHAR is really nothing more than a VARCHAR2/NVARCHAR2 in disguise makes me of the opinion that there are really only two character string types to ever consider, namely VARCHAR2 and NVARCHAR2. I have never found a use for the CHAR type in any application. Since a CHAR type always blank pads the resulting string out to a fixed width, we discover rapidly that it consumes maximum storage both in the table segment and any index segments. That would be bad enough, but there is another important reason to avoid CHAR/NCHAR types: they create confusion in applications that need to retrieve this information (many cannot “find” their data after storing it). 

Source citation : Book Oracle Database Architecture 

answered Jan 6, 2016 by slow_learner
edited Jun 7, 2016 by slow_learner