Click here to Skip to main content
15,936,983 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As per my understanding Char(2) length is 2 bytes and for CHAR(2 CHAR) column length is 2 characters. But CHAR(2) will also store 2 characters only. Please explain the difference between them.
Thank you.
Posted
Comments
Sanjay Chauhan02 12-Mar-14 9:15am    
No reply :(
CHill60 12-Mar-14 9:15am    
Did you really mean CHAR(2 CHAR) or did you mean VARCHAR2(2)?
Sanjay Chauhan02 12-Mar-14 9:20am    
I mean CHAR(2 CHAR) only

1 solution

This comes down what is meant by a "character". Typically (historically) a character would have been stored in a single byte. Nowadays you can have multi-byte characters (e.g. chinese characters can be stored on the database).

In order to ensure that the database can handle these and allocates sufficient space, you can insist that the field can hold 2 characters regardless of how many bytes are used to represent each character.
CHAR(2) is the same as CHAR(2 BYTE) which assumes single-byte characters are used.

This article is about this topic - "character semantics"[^] - and explains it better than my attempt. It focusses on varchar2 but the same applies to char.
 
Share this answer
 
Comments
Sanjay Chauhan02 12-Mar-14 11:44am    
Thanks. Much clear now.
CHill60 12-Mar-14 12:01pm    
My pleasure!
Maciej Los 12-Mar-14 17:52pm    
Deserves for 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900