GeekInterview.com
Series: Subject: Topic:
Question: 88 of 284

char(20) = 'name'
varchar2(20)='name'
When comparing these two values, are the spaces padded in char are considered or not? Are both values equal?

Asked by: Interview Candidate | Asked on: Sep 12th, 2007
Showing Answers 1 - 6 of 6 Answers

In Char type spaces will be padded after 'name' uptp max length 20.
in Varchar spaces will not be padded.

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

Answered On : Sep 26th, 2007

While comparing a char value to a Varchar spaces will be counted so your example fails

Regards
Mala

  
Login to rate this answer.
Sudhir Sorout

Answered On : Feb 8th, 2008

View all answers by Sudhir Sorout

Spaces will pad, both value will be different, Use this procedure your doubt will be clear


create or
replace procedure test2
as

   x varchar(20):='sudhir';

   y char(20):='sudhir';


   begin

   if(x=y) then


     dbms_output
.put_line('both are equal');


   else

     dbms_output
.put_line('both are not equal');


   end

if;

end;

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

You can check it using the following procedure

create or replace procedure test as

v_name1  char(20) := 'name';
v_name2  varchar2(20) := 'name';

begin

if v_name1 = v_name2 then
dbms_output.put_line('Both the words are same');
else
dbms_output.put_line('Both the words are different');
end if;
end;


The output is
Both the words are different.

if rtrim(v_name1) = v_name2 then

if you use rtrim for char data it will diplay the message
two words are same.

This is because
Char is a fixed length datatype and values are padded with blank spaces to match specified length.
Varchar2 is variable length datatype.

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

Answered On : May 20th, 2008

View all answers by mosam

ans is both values are not equal  char(20)='name' covered in memorey areea is 20 but varchar2(20)='name' covered in memorey areea is 4 becoze char is fixed lenth char data type but varchar2 is variable lenth char data type

  
Login to rate this answer.
javedans

Answered On : Jul 8th, 2009

View all answers by javedans

Spaces will be padded with y variable,its means y will store y='sudhir              ' . while x only store 6 six character so both string will not be equal

create or replace procedure test2 as
   x varchar(20):='sudhir'
;
   y char(20):='sudhir';

   begin
   if(x=y) then

     dbms_output.put_line('both are equal');
   else
     dbms_output.put_line('both are not equal');
   end
if;
end;

  
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

Ads

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.