Saturday, 20 February 2016

DIFFERENCE BETWEEN CHAR(SIZE) AND VARCHAR2(SIZE)

The Difference Between Char(size) & Varchar2(size) is observed in executing below program:

DECLARE
a CHAR(15):='&a';
b VARCHAR2(15):='&b';
BEGIN
IF(a=b)
DBMS_OUTPUT.PUT_LINE('Both the Strings are Equal');
ELSE
DBMS_OUTPUT.PUT_LINE('Both the Strings are not Equal');
END IF;
END;

OUTPUT:
Enter the Value of a=raj
Enter the Value of b=raj
Both the Strings are Not Equal

Explanation:
raj is a 3 character string remaining 12 characters memory assigned as spaces in CHAR(Size)
but in VARCHAR2(size) the remaining 12 characters memory will be set free i.e., unused or deleted.
Then  length(raj) in CHAR(15) data type is 15 and length(raj) in VARCHAR2(15) data type is 3
so 15=3 is false.
                                                                                                                                          

No comments:

Post a Comment

If you Like my blog Spread it and help friends for whom this blog is useful for their career.