These following lines came from 
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:123212348063
Or you might visit 
http://www.orafaq.com/faq/what_is_the_difference_between_varchar_varchar2_and_char_data_types

You Asked
I have a database column that shall store data always 
10 characters long. Which datatype should I use for it CHAR or 
VARCHAR2 and What is the specific reason for using that datatype ?

 

and we said...
A CHAR datatype and VARCHAR2 datatype are stored identically (eg: the word 
'WORD' stored 
in a CHAR(4) and a varchar2(4) consume exactly the same amount of space on 
disk, both 
have leading byte counts).

The difference between a CHAR and a VARCHAR is that a CHAR(n) will ALWAYS be N 
bytes 
long, it will be blank padded upon insert to ensure this.  A varchar2(n) on the 
other 
hand will be 1 to N bytes long, it will NOT be blank padded.

Using a CHAR on a varying width field can be a pain due to the search semantics 
of CHAR.  
Consider the following examples:

ops$tk...@8i> create table t ( x char(10) );
Table created.

ops$tk...@8i> insert into t values ( 'Hello' );
1 row created.

ops$tk...@8i> select * from t where x = 'Hello';

X
----------
Hello

ops$tk...@8i> variable y varchar2(25)
ops$tk...@8i> exec :y := 'Hello'
PL/SQL procedure successfully completed.

ops$tk...@8i> select * from t where x = :y;
no rows selected

ops$tk...@8i> select * from t where x = rpad(:y,10);

X
----------
Hello


Notice how when doing the search with a varchar2 variable (almost every tool in 
the world 
uses this type), we have to rpad() it to get a hit.

If the field is in fact ALWAYS 10 bytes long, using a CHAR will not hurt -- 
HOWEVER, it 
will not help either.  

The only time I personally use a CHAR type is for CHAR(1).  And that is only 
because its 
faster to type char(1) then varchar2(1) -- it offers no advantages.   



________________________________
From: Roberd Wilson <[email protected]>
To: [email protected]
Sent: Thursday, August 13, 2009 11:30:40 AM
Subject: [indo-oracle] tanya beda tipe data varchar dengan varchar2

  
dear all,

mau tanya bedanya antara tipe data varchar dan varchar2 di database oracle apa 
ya??
thanks be4..

[Non-text portions of this message have been removed]


   


      

[Non-text portions of this message have been removed]

Kirim email ke