Home » SQL & PL/SQL » SQL & PL/SQL » Char Versus Varchar
Char Versus Varchar [message #315488] Mon, 21 April 2008 13:11 Go to next message
shrinika
Messages: 266
Registered: April 2008
Senior Member
Dear all, I have question in specifying CHAR and VARCHAR data type length in oracle. In oracle table, the maximum length of CHAR is 2000. Maximum length of VARCHAR is 4000.

Let us say, if we spcify VARCHAR2(4000), and enter the data 'Hello', it occupies only 5 byte. It would not take all 4000 Bytes. In this scenario, why do we need CHAR type. We can specify VARCHAR2(4000) in all over the place where ever we use CHAR type.

The problem here is, if we specify CHAR(5) in oracle table, and latter the data length increase, then we have to change the field length. Instead of that, if we have VARCHAR2(4000), Then we do not need to make the field length change...

Please let me know your thoughts...

Regards
Govind
Re: Char Versus Varchar [message #315492 is a reply to message #315488] Mon, 21 April 2008 13:17 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
govindts wrote on Mon, 21 April 2008 20:11
In this scenario, why do we need CHAR type. We can specify VARCHAR2(4000) in all over the place where ever we use CHAR type.

These are two different things.
First of all: in 99% of all cases, indeed we don't need CHAR; we can use varchar2 for strings instead.
On the other hand: we don't want to use varchar2(4000) for everything, because using a max length is a way to restrict our data. You can compare it with the habit to declare numbers as NUMBER and dates as DATE. We could declare those as varchar2(4000) too, but we want to restrict the contents of those variables, so we declare the type to be restrictive.
Re: Char Versus Varchar [message #315496 is a reply to message #315492] Mon, 21 April 2008 13:23 Go to previous message
shrinika
Messages: 266
Registered: April 2008
Senior Member
Frank, I agree your points.
Previous Topic: sql to display record from T1 not found in T2
Next Topic: View access
Goto Forum:
  


Current Time: Fri Dec 02 18:38:51 CST 2016

Total time taken to generate the page: 0.53251 seconds