Easy learning with example program codes

What is the difference between CHAR and VARCHAR2 datatype in SQL?

Char type refers to fixed size datatype. So if we declare it with 10 bytes, then it always stores 10 bytes in the database and it doesn’t matter whether we store any text or just empty 10 bytes

Varchar2 represents a datatype of variable size, it’s size depends on how many bytes you are actually going to store in the database. The number we specify is just the maximum number of bytes that can be stored.  Minimum is 1 byte.

We should use CHAR when we know the exact length of the value in advance, database can then manipulate with it better and faster since it knows the exact length. Otherwise use VARCHAR2.


username VARCHAR2(255),
zip_code CHAR(6) //Fixed size zip code

Related topics

Please follow and like us:
Posted in SQL   

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki