What is difference between CHAR and VARCHAR2

Editorial / Best Answer

Answered by: srinivasan

  • Aug 16th, 2005


A varchar2 datatype, when stored in a database table, uses only the space  
allocated to it. If you have a varchar2(1999) and put 50 bytes in the table, we  
will use 52 bytes (leading length byte). 
 
A char datatype, when stored in a database table, always uses the maximum length  
and is blank padded. If you have char(1999) and put 50 bytes into it, it will  
consume 2001 bytes (leading length field is present on char's as well). 
 
In the database -- a CHAR is a VARCHAR that is blank padded to its maximum  
length. 

Showing Answers 1 - 6 of 6 Answers

bharath

  • May 30th, 2005
 

char is a fixed length charater data type. 
varchar is a variable length length character data type.

sajida

  • Jun 10th, 2005
 

Char will store null values even if the data inside the field is less than the specified length. Storage will be same as specified length. 
Varchar2 will store null values, if data is less than specified length, storage will be that much only.

srinivasan

  • Aug 16th, 2005
 

A varchar2 datatype, when stored in a database table, uses only the space  
allocated to it. If you have a varchar2(1999) and put 50 bytes in the table, we  
will use 52 bytes (leading length byte). 
 
A char datatype, when stored in a database table, always uses the maximum length  
and is blank padded. If you have char(1999) and put 50 bytes into it, it will  
consume 2001 bytes (leading length field is present on char's as well). 
 
In the database -- a CHAR is a VARCHAR that is blank padded to its maximum  
length. 

  Was this answer useful?  Yes

AISHWARYA

  • Jan 24th, 2012
 

Char : In char we need to specify the character length before using it ,no further changes can be done in char length and if charlength s not up to the specified length then rest of the spaces will be wasted .

varchar2 : we should specify the length but we can make changes ,if length of the character is not up to to the specified length the space will be used for some other purpose and it will not be wasted.

Code
  1. CREATE TABLE aa(id int PRIMARY KEY,name VARCHAR2(25));

  Was this answer useful?  Yes

gopalakrishna

  • Jul 28th, 2015
 

char is a data type based on the given size memory is used
varchar2 based on the given characters memory is used

  Was this answer useful?  Yes

Nitin Yadav

  • Nov 9th, 2017
 

Char is fixed and varchar 2 is variable.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions