GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 197 of 241    Print  
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?

  
Total Answers and Comments: 6 Last Update: July 08, 2009     Asked by: ricky 
  
 Sponsored Links

 
 Best Rated Answer
Submitted 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;



Above answer was rated as good by the following members:
kperumal75, ratna82
September 21, 2007 07:59:51   #1  
ashwani_kumar527 Member Since: September 2007   Contribution: 1    

RE: char(20) = 'name'
In Char type spaces will be padded after 'name' uptp max length 20.
in Varchar spaces will not be padded.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
September 26, 2007 18:54:43   #2  
mala        

RE: char(20) = 'name'
While comparing a char value to a Varchar spaces will be counted so your example fails

Regards
Mala

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
February 08, 2008 03:54:02   #3  
Sudhir Sorout Member Since: February 2008   Contribution: 8    

RE: 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?
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;


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
May 13, 2008 04:55:01   #4  
krishnaindia2007 Member Since: September 2007   Contribution: 854    

RE: 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?

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.


 
Is this answer useful? Yes | No
May 20, 2008 22:12:14   #5  
mosam Member Since: May 2008   Contribution: 2    

RE: 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?
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
 
Is this answer useful? Yes | No
July 08, 2009 15:14:46   #6  
javedans Member Since: January 2009   Contribution: 8    

RE: 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?
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;


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape