What is the difference between char,varchar,varchar2?

Questions by praveen_garigipati   answers by praveen_garigipati

Showing Answers 1 - 17 of 17 Answers

pramod kumar

  • Apr 6th, 2006
 

no diff between varchar and varchar2

char store only chacter type but varchar2 store variable chacters.

also varchar2 shirinks the space if not fully filled but char cant.

  Was this answer useful?  Yes

brahma reddy kurre

  • Jul 7th, 2006
 

Hi there is no variable type called varchar..

So lest come to the main point.

Here I am explaining wiht example

1. Varchar2 name [100]="brahma reddy"; // here it uses only the required bytes, it uses 12 bytes and remaining 88 bytes will be freed

2. char name [100]="brahma reddy"; // here remaining bytes will be filled with null values.

Thank you

Brahma

Jitendra Kumar

  • Jul 20th, 2006
 

I read all the answer that has been posted all are different According to me :- in a varchar variable if we define the size 10 weather u enter or not but in varchar2 variable will take space in memory only when u enter the value and it will take space in memory length u enter.

  Was this answer useful?  Yes

Sphurti

  • Aug 11th, 2006
 

Hi,

No Jitender is wrong. As explained in one of the reply.

Char is the datatype that occupies complete space declared whether used or not. ie:- If any field is declared as char(10) then this field for all records will occupy complete 10 bytes whether the value stored in it is 1 byte or 10 byte.

Whereas Varchar2, as the first 3 characters explains Var-Variable, will occupy only the bytes for the value entered in the field.

So ideally it is good practice to declare fields like emp_flg or any other fields which we are sure will have fixed length value as Char. 

  Was this answer useful?  Yes

Amritpal

  • May 26th, 2007
 

Hello ppl,
i think u all r got confused with this char and varchar.
here is it
char : will allocate values upto full length specified using whitespaces
varchar: will allocate limited memory which is occupied by data. no padding is there.
varchar2: same as varchar but has some special internal benefits which helps oracle perform fast.
Now question is diff bw varchar/varchar2?
as we all know for RDBMS Codd NewMan provides thumb rules n to just satisfy
those rules Oracle created these two types os datatypes char/varchar
just to fulfill ANSI standard for RDBMS.
whereas oracle realises that varchar datatype can further more be enhansed so varchar2 datatype was introduced.

hope this helps u.
bye
amrit

  Was this answer useful?  Yes

char store only chacter type but varchar2 store variable chacters. also varchar2 shirinks the space if not fully filled but char cant.
for more clear
create table gopal (name char(8),name varchar(8));
in this table if u inserts any values let us take  ('india') .in the case of char data type, 'india' contains 5 chrecters but we have intialised for 8 chrecters rest 3 charecters will inserted as blank spaces,if u what use this column for filtering(where class)u shoud give ('india') as ('india   ') than only rows will come
where in varchar datatype u can give as 'india' for rust of charecters padding will applied

  Was this answer useful?  Yes

kaustavban

  • Jun 5th, 2008
 

The most important difference is that CHAR is padded with spaces and VARCHAR is not. For example, if you have:

CREATE TABLE t1 (
c1 VARCHAR(2),
c2 CHAR(2)
);

INSERT INTO t1 (c1,c2) VALUES ('a', 'a');

The column c1 will contain value 'a', while column c2 will contain value 'a ' with additional space. Trailing spaces are ignored when doing comparisons, so both columns would match the

WHERE c = 'a'

  Was this answer useful?  Yes

kaustavban

  • Jun 5th, 2008
 

The char is a fixed-length character data type, the varchar is a variable-length character data type.Because char is a fixed-length data type, the storage size of the char value is equal to the maximum size for this column. Because varchar is a variable-length data type, the storage size of the varchar value is the actual length of the data entered, not the maximum size for this column.You can use char when the data entries in a column are expected to be the same size.You can use varchar when the data entries in a column are expected to vary considerably in size.

getadoll

  • Jan 17th, 2009
 

The char is a fixed-length character data type, the varchar is a variable-length character data type.

Because char is a fixed-length data type, the storage size of the char value is equal to the maximum size for this column. Because varchar is a variable-length data type, the storage size of the varchar value is the actual length of the data entered, not the maximum size for this column.

You can use char when the data entries in a column are expected to be the same size.
You can use varchar when the data entries in a column are expected to vary considerably in size.VARCHAR2 is used to store variable length character strings. The string value's length will be stored on disk with the value itself.

  Was this answer useful?  Yes

bismita

  • Jan 24th, 2009
 

As I believe there is no difference between VARCHAR and VARCHAR2 except that VARCHAR2 is the latest released one.CHAR datatype represents fixed length hence not compressed while giving a value of less length. Instead it will padded blanks while storing. But VRACHAR s are variable length characters and in case of  less length of the characters it will be compressed and stored.

  Was this answer useful?  Yes

vijaydeep

  • Mar 1st, 2009
 

The advanced type is varchar2 in latest versions.
The simplest way to define is the char i.e. char(s): Fixed length character value of size s
and the varchar2(s): Variable-length character value of maximum size s
ie. char(s) can enter only char type,
where as varchar2()can accept number and char type also.

  Was this answer useful?  Yes

srinivas

  • Sep 16th, 2011
 

Char: char is fixed length data type
VarChar:Varchar are variable in length In that varchar take the additional Memory bytes depending on the Declare the size of the variable.

  Was this answer useful?  Yes

ii

  • Sep 21st, 2011
 

Code
  1.   SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dBConnection"].ToString());

  2.         con.Open();

  3.         DataSet ds = new DataSet();

  4.         SqlCommand cmd = new SqlCommand("GetICon", con);

  5.         SqlDataAdapter adap = new SqlDataAdapter(cmd);

  6.         cmd.CommandType = CommandType.StoredProcedure;

  7.  

  8.         adap.Fill(ds);

  9.         return ds.Tables[0];

  Was this answer useful?  Yes

lina

  • Aug 22nd, 2012
 

1.CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. If this type is used to store varibale length strings, it will waste a lot of disk space.
2.VARCHAR is going to be replaced by VARCHAR2 in next version. So, Oracle suggests the use VARCHAR2 instead of VARCHAR while declaring datatype.
3. VARCHAR can store up to 2000 bytes of characters while VARCHAR2 can store up to 4000 bytes of characters.
4. If we declare datatype as VARCHAR then it will occupy space for NULL values, In case of VARCHAR2 datatype it will not occupy any space.
Varchar stores alphanumeric values without padding the unused memory locations.
Varchar2 is also used to store alphanumeric values with padding the unused memory locations by using varchar2 we are saving the memory locations.

  Was this answer useful?  Yes

1.CHAR should be used for storing fix length character strings. String values will be space/blank padded before stored on disk. If this type is used to store varibale length strings, it will waste a lot of disk space.
2.VARCHAR is going to be replaced by VARCHAR2 in next version. So, Oracle suggests the use VARCHAR2 instead of VARCHAR while declaring datatype.
3. VARCHAR can store up to 2000 bytes of characters while VARCHAR2 can store up to 4000 bytes of characters.
4. If we declare datatype as VARCHAR then it will occupy space for NULL values, In case of VARCHAR2 datatype it will not occupy any space.
Varchar stores alphanumeric values without padding the unused memory locations.
Varchar2 is also used to store alphanumeric values with padding the unused memory locations by using varchar2 we are saving the memory locations.

  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.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions