GeekInterview.com
Series: Subject: Topic:
Question: 334 of 377

what is the difference between char,varchar,varchar2?

Asked by: praveen_garigipati | Member Since Sep-2005 | Asked on: Apr 5th, 2006

View all questions by praveen_garigipati   View all answers by praveen_garigipati

Showing Answers 1 - 17 of 17 Answers
pramod kumar

Answered On : 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.

  
Login to rate this answer.
hussain

Answered On : Apr 14th, 2006

View all answers by hussain

char is fixed length data type whereas varchar & varchar2 are variable in length

  
Login to rate this answer.
brahma reddy kurre

Answered On : Jul 7th, 2006

Hi there is no variable type called varchar.. So lest come to the main point.Here I am explaining wiht example1. Varchar2 name [100]="brahma reddy"; // here it uses only the required bytes, it uses 12 bytes and remaining 88 bytes will be freed2. char name [100]="brahma reddy"; // here remaining bytes will be filled with null values.Thank youBrahma

Yes  1 User has rated as useful.
  
Login to rate this answer.
Jitendra Kumar

Answered On : 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.

  
Login to rate this answer.
Sphurti

Answered On : 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. 

  
Login to rate this answer.
Amritpal

Answered On : May 26th, 2007

Hello ppl,i think u all r got confused with this char and varchar.here is itchar : will allocate values upto full length specified using whitespacesvarchar: 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 satisfythose 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.byeamrit

  
Login to rate this answer.

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 comewhere in varchar datatype u can give as 'india' for rust of charecters padding will applied

  
Login to rate this answer.
kaustavban

Answered On : Jun 5th, 2008

View all answers by kaustavban

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 theWHERE c = 'a'

  
Login to rate this answer.
kaustavban

Answered On : Jun 5th, 2008

View all answers by kaustavban

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.

Yes  2 Users have rated as useful.
  
Login to rate this answer.
getadoll

Answered On : Jan 17th, 2009

View all answers by getadoll

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.

  
Login to rate this answer.

Char specifies fixed length characters only.varchar & varchar2 is  specifies a variable length character only

  
Login to rate this answer.
bismita

Answered On : Jan 24th, 2009

View all answers by bismita

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.

  
Login to rate this answer.
vijaydeep

Answered On : Mar 1st, 2009

View all answers by vijaydeep

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 sand the varchar2(s): Variable-length character value of maximum size sie. char(s) can enter only char type,
where as varchar2()can accept number and char type also.

  
Login to rate this answer.
srinivas

Answered On : 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.

  
Login to rate this answer.
ii

Answered On : 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];

  
Login to rate this answer.
lina

Answered On : 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.

  
Login to rate this answer.
lipika mishra

Answered On : Aug 22nd, 2012

View all answers by lipika mishra

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.

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.